1--TEST-- 2openssl_pkcs7_decrypt() tests 3--EXTENSIONS-- 4openssl 5--FILE-- 6<?php 7$infile = __DIR__ . "/cert.crt"; 8$privkey = "file://" . __DIR__ . "/private_rsa_1024.key"; 9$encrypted = tempnam(sys_get_temp_dir(), "ssl"); 10if ($encrypted === false) 11 die("failed to get a temporary filename!"); 12$outfile = tempnam(sys_get_temp_dir(), "ssl"); 13if ($outfile === false) { 14 unlink($outfile); 15 die("failed to get a temporary filename!"); 16} 17 18$single_cert = "file://" . __DIR__ . "/cert.crt"; 19$headers = array("test@test", "testing openssl_pkcs7_encrypt()"); 20$wrong = "wrong"; 21$empty = ""; 22$cipher = OPENSSL_CIPHER_AES_128_CBC; 23 24openssl_pkcs7_encrypt($infile, $encrypted, $single_cert, $headers, 0, $cipher); 25var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $single_cert, $privkey)); 26var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, openssl_x509_read($single_cert), $privkey)); 27var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $single_cert, $wrong)); 28var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $wrong, $privkey)); 29var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, null, $privkey)); 30var_dump(openssl_pkcs7_decrypt($wrong, $outfile, $single_cert, $privkey)); 31var_dump(openssl_pkcs7_decrypt($empty, $outfile, $single_cert, $privkey)); 32var_dump(openssl_pkcs7_decrypt($encrypted, $empty, $single_cert, $privkey)); 33var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $empty, $privkey)); 34var_dump(openssl_pkcs7_decrypt($encrypted, $outfile, $single_cert, $empty)); 35 36if (file_exists($encrypted)) { 37 echo "true\n"; 38 unlink($encrypted); 39} 40if (file_exists($outfile)) { 41 echo "true\n"; 42 unlink($outfile); 43} 44?> 45--EXPECTF-- 46bool(true) 47bool(true) 48 49Warning: openssl_pkcs7_decrypt(): Unable to get private key in %s on line %d 50bool(false) 51 52Warning: openssl_pkcs7_decrypt(): X.509 Certificate cannot be retrieved in %s on line %d 53bool(false) 54 55Warning: openssl_pkcs7_decrypt(): X.509 Certificate cannot be retrieved in %s on line %d 56bool(false) 57bool(false) 58bool(false) 59bool(false) 60 61Warning: openssl_pkcs7_decrypt(): X.509 Certificate cannot be retrieved in %s on line %d 62bool(false) 63 64Warning: openssl_pkcs7_decrypt(): Unable to get private key in %s on line %d 65bool(false) 66true 67true 68