1--TEST--
2void openssl_free_key ( resource $key_identifier );
3--CREDITS--
4marcosptf - <marcosptf@yahoo.com.br> - @phpsp - sao paulo - br
5--EXTENSIONS--
6openssl
7--SKIPIF--
8<?php
9if (!@openssl_pkey_new())
10    die("skip cannot create private key");
11?>
12--FILE--
13<?php
14echo "Creating private key\n";
15
16$conf = array('config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf');
17$privkey = openssl_pkey_new($conf);
18
19if ($privkey === false)
20    die("failed to create private key");
21
22$passphrase = "banana";
23$key_file_name = tempnam(sys_get_temp_dir(), "ssl");
24if ($key_file_name === false)
25    die("failed to get a temporary filename!");
26
27echo "Export key to file\n";
28
29openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase, $conf) or die("failed to export to file $key_file_name");
30
31echo "Load key from file - array syntax\n";
32
33$loaded_key = openssl_pkey_get_private(array("file://$key_file_name", $passphrase));
34
35if ($loaded_key === false)
36    die("failed to load key using array syntax");
37
38openssl_free_key($loaded_key);
39
40echo "Load key using direct syntax\n";
41
42$loaded_key = openssl_pkey_get_private("file://$key_file_name", $passphrase);
43
44if ($loaded_key === false)
45    die("failed to load key using direct syntax");
46
47openssl_free_key($loaded_key);
48
49echo "Load key manually and use string syntax\n";
50
51$key_content = file_get_contents($key_file_name);
52$loaded_key = openssl_pkey_get_private($key_content, $passphrase);
53
54if ($loaded_key === false)
55    die("failed to load key using string syntax");
56
57openssl_free_key($loaded_key);
58
59echo "OK!\n";
60
61@unlink($key_file_name);
62?>
63--EXPECTF--
64Creating private key
65Export key to file
66Load key from file - array syntax
67
68Deprecated: Function openssl_free_key() is deprecated since 8.0, as OpenSSLAsymmetricKey objects are freed automatically in %s on line %d
69Load key using direct syntax
70
71Deprecated: Function openssl_free_key() is deprecated since 8.0, as OpenSSLAsymmetricKey objects are freed automatically in %s on line %d
72Load key manually and use string syntax
73
74Deprecated: Function openssl_free_key() is deprecated since 8.0, as OpenSSLAsymmetricKey objects are freed automatically in %s on line %d
75OK!
76