xref: /PHP-7.0/ext/openssl/tests/bug73833.phpt (revision 7b392c71)
1--TEST--
2Bug #73833: null character not allowed in openssl_pkey_get_private
3--SKIPIF--
4<?php
5if (!extension_loaded("openssl")) die("skip openssl not loaded");
6?>
7--FILE--
8<?php
9$passwords = ["abc\x00defghijkl", "abcdefghikjl"];
10$conf = ['config' => __DIR__ . DIRECTORY_SEPARATOR . 'openssl.cnf'];
11
12foreach($passwords as $password) {
13	$key = openssl_pkey_new($conf);
14
15	if (openssl_pkey_export($key, $privatePEM, $password, $conf) === false) {
16		echo "Failed to encrypt.\n";
17	} else {
18		echo "Encrypted!\n";
19	}
20	if (openssl_pkey_get_private($privatePEM, $password) === false) {
21		echo "Failed to decrypt.\n";
22	} else {
23		echo "Decrypted!\n";
24	}
25}
26?>
27--EXPECT--
28Encrypted!
29Decrypted!
30Encrypted!
31Decrypted!
32