File: 001.phpt

package info (click to toggle)
php8.2 8.2.29-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 209,600 kB
  • sloc: ansic: 736,658; php: 33,046; sh: 11,432; cpp: 7,005; pascal: 4,448; javascript: 3,112; asm: 2,404; yacc: 2,222; xml: 1,784; makefile: 689; awk: 148
file content (84 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
--TEST--
OpenSSL private key functions
--EXTENSIONS--
openssl
--SKIPIF--
<?php
if (!@openssl_pkey_new()) die("skip cannot create private key");
?>
--FILE--
<?php
echo "Creating private key\n";

$conf = array('config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf');
$privkey = openssl_pkey_new($conf);

if ($privkey === false) {
    die("failed to create private key");
}

$passphrase = "banana";
$key_file_name = __DIR__ . '/001-tmp.key';
if ($key_file_name === false) {
    die("failed to get a temporary filename!");
}

echo "Export key to file\n";

if (!openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase, $conf)) {
    die("failed to export to file $key_file_name");
}
var_dump($privkey instanceof OpenSSLAsymmetricKey);

echo "Load key from file - array syntax\n";

$loaded_key = openssl_pkey_get_private(array("file://$key_file_name", $passphrase));

if ($loaded_key === false) {
    die("failed to load key using array syntax");
}

openssl_pkey_free($loaded_key);

echo "Load key using direct syntax\n";

$loaded_key = openssl_pkey_get_private("file://$key_file_name", $passphrase);

if ($loaded_key === false) {
    die("failed to load key using direct syntax");
}

openssl_pkey_free($loaded_key);

echo "Load key manually and use string syntax\n";

$key_content = file_get_contents($key_file_name);
$loaded_key = openssl_pkey_get_private($key_content, $passphrase);

if ($loaded_key === false) {
    die("failed to load key using string syntax");
}
openssl_pkey_free($loaded_key);

echo "OK!\n";

?>
--CLEAN--
<?php
$key_file_name = __DIR__ . DIRECTORY_SEPARATOR . '001-tmp.key';
@unlink($key_file_name);
?>
--EXPECTF--
Creating private key
Export key to file
bool(true)
Load key from file - array syntax

Deprecated: Function openssl_pkey_free() is deprecated in %s on line %d
Load key using direct syntax

Deprecated: Function openssl_pkey_free() is deprecated in %s on line %d
Load key manually and use string syntax

Deprecated: Function openssl_pkey_free() is deprecated in %s on line %d
OK!