openssl_free_key.phpt 1.9 KB

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