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 = base64_encode("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, 0, $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));
22
23?>
24--EXPECTF--
25Warning: openssl_encrypt(): Using an empty Initialization Vector (iv) is potentially insecure and not recommended in %s on line %d
26string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
27string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
28bool(false)
29
30Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
31bool(false)
32bool(false)
33
34Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
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