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));
22var_dump(openssl_decrypt(array(), $method, $password));
23var_dump(openssl_decrypt($encrypted, array(), $password));
24var_dump(openssl_decrypt($encrypted, $method, array()));
25
26// invalid using of an authentication tag
27var_dump(openssl_encrypt($data, $method, $password, 0, $iv, $wrong));
28?>
29--EXPECTF--
30Warning: openssl_encrypt(): Using an empty Initialization Vector (iv) is potentially insecure and not recommended in %s on line %d
31string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
32string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
33bool(false)
34
35Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
36bool(false)
37bool(false)
38
39Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
40bool(false)
41
42Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
43bool(false)
44
45Warning: openssl_decrypt(): Unknown cipher algorithm in %s on line %d
46bool(false)
47
48Warning: openssl_decrypt() expects parameter 1 to be string, array given in %s on line %d
49NULL
50
51Warning: openssl_decrypt() expects parameter 2 to be string, array given in %s on line %d
52NULL
53
54Warning: openssl_decrypt() expects parameter 3 to be string, array given in %s on line %d
55NULL
56
57Warning: openssl_encrypt(): The authenticated tag cannot be provided for cipher that doesn not support AEAD in %s on line %d
58string(44) "yof6cPPH4mLee6TOc0YQSrh4dvywMqxGUyjp0lV6+aM="
59