"Fossies" - the Fresh Open Source Software Archive 
Member "hhvm-HHVM-4.165.0/hphp/test/zend/good/ext/openssl/tests/001.php" (22 Jul 2022, 1498 Bytes) of package /linux/www/hhvm-HHVM-4.165.0.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
1 <?hh <<__EntryPoint>> function main(): void {
2 echo "Creating private key\n";
3
4 /* stack up some entropy; performance is not critical,
5 * and being slow will most likely even help the test.
6 */
7 for ($z = "", $i = 0; $i < 1024; $i++) {
8 $z .= $i * $i;
9 if (function_exists("usleep"))
10 usleep($i);
11 }
12
13 $privkey = openssl_pkey_new();
14
15 if ($privkey === false)
16 die("failed to create private key");
17
18 $passphrase = "banana";
19 $key_file_name = tempnam("/tmp", "ssl");
20 if ($key_file_name === false)
21 die("failed to get a temporary filename!");
22
23 echo "Export key to file\n";
24
25 openssl_pkey_export_to_file($privkey, $key_file_name, $passphrase) || die("failed to export to file $key_file_name");
26
27 echo "Load key from file - array syntax\n";
28
29 $loaded_key = openssl_pkey_get_private(varray["file://$key_file_name", $passphrase]);
30
31 if ($loaded_key === false)
32 die("failed to load key using array syntax");
33
34 openssl_pkey_free($loaded_key);
35
36 echo "Load key using direct syntax\n";
37
38 $loaded_key = openssl_pkey_get_private("file://$key_file_name", $passphrase);
39
40 if ($loaded_key === false)
41 die("failed to load key using direct syntax");
42
43 openssl_pkey_free($loaded_key);
44
45 echo "Load key manually and use string syntax\n";
46
47 $key_content = file_get_contents($key_file_name);
48 $loaded_key = openssl_pkey_get_private($key_content, $passphrase);
49
50 if ($loaded_key === false)
51 die("failed to load key using string syntax");
52
53 openssl_pkey_free($loaded_key);
54
55 echo "OK!\n";
56
57 @unlink($key_file_name);
58 }