openssl_encrypt_error.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. --TEST--
  2. openssl_encrypt() error tests
  3. --SKIPIF--
  4. <?php if (!extension_loaded("openssl")) print "skip"; ?>
  5. --FILE--
  6. <?php
  7. $data = "openssl_encrypt() tests";
  8. $method = "AES-128-CBC";
  9. $password = "openssl";
  10. $iv = str_repeat("\0", openssl_cipher_iv_length($method));
  11. $wrong = "wrong";
  12. $object = new stdclass;
  13. $arr = array(1);
  14. // wrong parameters tests
  15. var_dump(openssl_encrypt($data, $wrong, $password));
  16. var_dump(openssl_encrypt($object, $method, $password));
  17. var_dump(openssl_encrypt($data, $object, $password));
  18. var_dump(openssl_encrypt($data, $method, $object));
  19. var_dump(openssl_encrypt($arr, $method, $object));
  20. var_dump(openssl_encrypt($data, $arr, $object));
  21. var_dump(openssl_encrypt($data, $method, $arr));
  22. // invalid using of an authentication tag
  23. var_dump(openssl_encrypt($data, $method, $password, 0, $iv, $wrong));
  24. // padding of the key is disabled
  25. var_dump(openssl_encrypt($data, $method, $password, OPENSSL_DONT_ZERO_PAD_KEY, $iv));
  26. ?>
  27. --EXPECTF--
  28. Warning: openssl_encrypt(): Unknown cipher algorithm in %s on line %d
  29. bool(false)
  30. Warning: openssl_encrypt() expects parameter 1 to be string, object given in %s on line %d
  31. NULL
  32. Warning: openssl_encrypt() expects parameter 2 to be string, object given in %s on line %d
  33. NULL
  34. Warning: openssl_encrypt() expects parameter 3 to be string, object given in %s on line %d
  35. NULL
  36. Warning: openssl_encrypt() expects parameter 1 to be string, array given in %s on line %d
  37. NULL
  38. Warning: openssl_encrypt() expects parameter 2 to be string, array given in %s on line %d
  39. NULL
  40. Warning: openssl_encrypt() expects parameter 3 to be string, array given in %s on line %d
  41. NULL
  42. Warning: openssl_encrypt(): The authenticated tag cannot be provided for cipher that doesn not support AEAD in %s on line %d
  43. string(44) "iPR4HulskuaP5Z6me5uImk6BqVyJG73+63tkPauVZYk="
  44. Warning: openssl_encrypt(): Key length cannot be set for the cipher method in %s on line %d
  45. bool(false)