1--TEST--
2openssl_pkey_export() with EC key
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip");
6if (!defined('OPENSSL_KEYTYPE_EC')) die("skip no EC available");
7?>
8--FILE--
9<?php
10$key = openssl_pkey_get_private('file://' . dirname(__FILE__) . '/private_ec.key');
11var_dump($key);
12
13$config_arg = array("config" => __DIR__ . DIRECTORY_SEPARATOR . "openssl.cnf");
14
15var_dump(openssl_pkey_export($key, $output, NULL, $config_arg));
16echo $output;
17
18// Load the private key from the exported pem string
19$details = openssl_pkey_get_details(openssl_pkey_get_private($output));
20var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
21
22// Export key with passphrase
23openssl_pkey_export($key, $output, 'passphrase', $config_arg);
24
25$details = openssl_pkey_get_details(openssl_pkey_get_private($output, 'passphrase'));
26var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
27
28// Read public key
29$pKey = openssl_pkey_get_public('file://' . dirname(__FILE__) . '/public_ec.key');
30var_dump($pKey);
31// The details are the same for a public or private key
32var_dump($details === openssl_pkey_get_details($pKey));
33
34
35// Export to file
36$tempname = tempnam(sys_get_temp_dir(), 'openssl_ec');
37var_dump(openssl_pkey_export_to_file($key, $tempname, NULL, $config_arg));
38$details = openssl_pkey_get_details(openssl_pkey_get_private('file://' . $tempname));
39var_dump(OPENSSL_KEYTYPE_EC === $details['type']);
40var_dump(is_resource($key));
41// Clean the temporary file
42@unlink($tempname);
43
44?>
45--EXPECTF--
46resource(%d) of type (OpenSSL key)
47bool(true)
48-----BEGIN EC PRIVATE KEY-----%a-----END EC PRIVATE KEY-----
49bool(true)
50bool(true)
51resource(%d) of type (OpenSSL key)
52bool(true)
53bool(true)
54bool(true)
55bool(true)
56