openssl_spki_new_basic.phpt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. --TEST--
  2. openssl_spki_new() test for creating SPKI string
  3. --SKIPIF--
  4. <?php
  5. if (!extension_loaded("openssl")) die("skip");
  6. ?>
  7. --FILE--
  8. <?php
  9. /* array of private key sizes to test */
  10. $key_sizes = array(1024, 2048, 4096);
  11. $pkeys = array();
  12. foreach ($key_sizes as $key_size) {
  13. $key_file = "file://" . dirname(__FILE__) . "/private_rsa_" . $key_size . ".key";
  14. $pkeys[] = openssl_pkey_get_private($key_file);
  15. }
  16. /* array of available hashings to test */
  17. $algo = array(
  18. OPENSSL_ALGO_MD4,
  19. OPENSSL_ALGO_MD5,
  20. OPENSSL_ALGO_SHA1,
  21. OPENSSL_ALGO_SHA224,
  22. OPENSSL_ALGO_SHA256,
  23. OPENSSL_ALGO_SHA384,
  24. OPENSSL_ALGO_SHA512,
  25. OPENSSL_ALGO_RMD160
  26. );
  27. /* loop over key sizes for test */
  28. foreach ($pkeys as $pkey) {
  29. /* loop to create and verify results */
  30. foreach ($algo as $value) {
  31. var_dump(openssl_spki_new($pkey, _uuid(), $value));
  32. }
  33. }
  34. /* generate a random challenge */
  35. function _uuid() {
  36. return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff),
  37. mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000,
  38. mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff),
  39. mt_rand(0, 0xffff), mt_rand(0, 0xffff));
  40. }
  41. ?>
  42. --EXPECTF--
  43. string(478) "%s"
  44. string(478) "%s"
  45. string(478) "%s"
  46. string(478) "%s"
  47. string(478) "%s"
  48. string(478) "%s"
  49. string(478) "%s"
  50. string(474) "%s"
  51. string(830) "%s"
  52. string(830) "%s"
  53. string(830) "%s"
  54. string(830) "%s"
  55. string(830) "%s"
  56. string(830) "%s"
  57. string(830) "%s"
  58. string(826) "%s"
  59. string(1510) "%s"
  60. string(1510) "%s"
  61. string(1510) "%s"
  62. string(1510) "%s"
  63. string(1510) "%s"
  64. string(1510) "%s"
  65. string(1510) "%s"
  66. string(1506) "%s"