1--TEST-- 2openssl_cms_encrypt() der test 3--EXTENSIONS-- 4openssl 5--FILE-- 6<?php 7$infile = __DIR__ . "/plain.txt"; 8$tname = tempnam(sys_get_temp_dir(), "ssl"); 9if ($tname === false) 10 die("failed to get a temporary filename!"); 11$cryptfile= $tname . ".der"; 12$decryptfile = $tname . ".out"; 13$single_cert = "file://" . __DIR__ . "/cert.crt"; 14$privkey = "file://" . __DIR__ . "/private_rsa_1024.key"; 15$headers = array("test@test", "testing openssl_cms_encrypt()"); 16$cipher = OPENSSL_CIPHER_AES_128_CBC; 17 18var_dump(openssl_cms_encrypt($infile, $cryptfile, $single_cert, $headers, OPENSSL_CMS_BINARY, OPENSSL_ENCODING_DER, $cipher)); 19if (openssl_cms_decrypt($cryptfile, $decryptfile, $single_cert, $privkey, OPENSSL_ENCODING_DER) == false) { 20 print "DER decrypt error\n"; 21 print "recipient:\n"; 22 readfile($single_cert); 23 print "input:\n"; 24 readfile($infile); 25 $der=file_get_contents($cryptfile); 26 print "outfile base64:\n" . base64_encode($der) . "\n--------\n"; 27 while (( $errstr=openssl_error_string()) != false) { 28 print $errstr . "\n"; 29 } 30} else { 31 readfile($decryptfile); 32} 33 34if (file_exists($cryptfile)) { 35 echo "true\n"; 36 unlink($cryptfile); 37} 38if (file_exists($decryptfile)) { 39 echo "true\n"; 40 unlink($decryptfile); 41} 42unlink($tname); 43?> 44--EXPECT-- 45bool(true) 46Now is the winter of our discontent. 47true 48true 49 50