openssl_public_encrypt_basic.phpt 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. openssl_public_encrypt() tests
  3. --SKIPIF--
  4. <?php if (!extension_loaded("openssl")) print "skip"; ?>
  5. --FILE--
  6. <?php
  7. $data = "Testing openssl_public_encrypt()";
  8. $privkey = "file://" . dirname(__FILE__) . "/private_rsa_1024.key";
  9. $pubkey = "file://" . dirname(__FILE__) . "/public.key";
  10. $wrong = "wrong";
  11. class test {
  12. function __toString() {
  13. return "test";
  14. }
  15. }
  16. $obj = new test;
  17. var_dump(openssl_public_encrypt($data, $encrypted, $pubkey));
  18. var_dump(openssl_public_encrypt($data, $encrypted, $privkey));
  19. var_dump(openssl_public_encrypt($data, $encrypted, $wrong));
  20. var_dump(openssl_public_encrypt($data, $encrypted, $obj));
  21. var_dump(openssl_public_encrypt($obj, $encrypted, $pubkey));
  22. openssl_private_decrypt($encrypted, $output, $privkey);
  23. var_dump($output);
  24. ?>
  25. --EXPECTF--
  26. bool(true)
  27. Warning: openssl_public_encrypt(): key parameter is not a valid public key in %s on line %d
  28. bool(false)
  29. Warning: openssl_public_encrypt(): key parameter is not a valid public key in %s on line %d
  30. bool(false)
  31. Warning: openssl_public_encrypt(): key parameter is not a valid public key in %s on line %d
  32. bool(false)
  33. bool(true)
  34. string(4) "test"