1--TEST--
2openssl_public_decrypt() tests
3--EXTENSIONS--
4openssl
5--FILE--
6<?php
7$data = "Testing openssl_public_decrypt()";
8$privkey = "file://" . __DIR__ . "/private_rsa_1024.key";
9$pubkey = "file://" . __DIR__ . "/public.key";
10$wrong = "wrong";
11
12openssl_private_encrypt($data, $encrypted, $privkey);
13var_dump(openssl_public_decrypt($encrypted, $output, $pubkey));
14var_dump($output);
15var_dump(openssl_public_decrypt($encrypted, $output2, $wrong));
16var_dump($output2);
17var_dump(openssl_public_decrypt($wrong, $output3, $pubkey));
18var_dump($output3);
19
20try {
21    var_dump(openssl_public_decrypt($encrypted, $output4, array()));
22    var_dump($output4);
23} catch (\ValueError $e) {
24    echo $e->getMessage() . \PHP_EOL;
25}
26
27try {
28    var_dump(openssl_public_decrypt($encrypted, $output5, array($pubkey)));
29    var_dump($output5);
30} catch (\ValueError $e) {
31    echo $e->getMessage() . \PHP_EOL;
32}
33var_dump(openssl_public_decrypt($encrypted, $output6, array($pubkey, "")));
34var_dump($output6);
35?>
36--EXPECTF--
37bool(true)
38string(32) "Testing openssl_public_decrypt()"
39
40Warning: openssl_public_decrypt(): key parameter is not a valid public key in %s on line %d
41bool(false)
42NULL
43bool(false)
44NULL
45Key array must be of the form array(0 => key, 1 => phrase)
46Key array must be of the form array(0 => key, 1 => phrase)
47bool(true)
48string(32) "Testing openssl_public_decrypt()"
49