1--TEST--
2openssl_decrypt() error tests
3--SKIPIF--
4<?php if (!extension_loaded("openssl")) print "skip"; ?>
5--FILE--
6<?php
7$data = "openssl_decrypt() tests";
8$method = "AES-128-CBC";
9$password = "openssl";
10$wrong = "wrong";
11$iv = str_repeat("\0", openssl_cipher_iv_length($method));
12
13$encrypted = openssl_encrypt($data, $method, $password);
14var_dump($encrypted); /* Not passing $iv should be the same as all-NULL iv, but with a warning */
15var_dump(openssl_encrypt($data, $method, $password, false, $iv));
16var_dump(openssl_decrypt($encrypted, $method, $wrong));
17var_dump(openssl_decrypt($encrypted, $wrong, $password));
18var_dump(openssl_decrypt($wrong, $method, $password));
19var_dump(openssl_decrypt($wrong, $wrong, $password));
20var_dump(openssl_decrypt($encrypted, $wrong, $wrong));
21var_dump(openssl_decrypt($wrong, $wrong, $wrong));
22var_dump(openssl_decrypt(array(), $method, $password));
23var_dump(openssl_decrypt($encrypted, array(), $password));
24var_dump(openssl_decrypt($encrypted, $method, array()));
25?>
26--EXPECTF--
27
28Warning: openssl_encrypt(): Using an empty Initialization Vector (iv) is potentially insecure and not recommended in %s on line %d
29string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
30string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
31bool(false)
32
33Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
34bool(false)
35bool(false)
36
37Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
38bool(false)
39
40Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
41bool(false)
42
43Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
44bool(false)
45
46Warning: openssl_decrypt() expects parameter 1 to be string, array given in %s on line %d
47NULL
48
49Warning: openssl_decrypt() expects parameter 2 to be string, array given in %s on line %d
50NULL
51
52Warning: openssl_decrypt() expects parameter 3 to be string, array given in %s on line %d
53NULL
54