使用php中的openssl_private_encrypt加密二进制文件

时间:2015-03-05 19:47:01

标签: php encryption digital-signature php-openssl

我想使用Symfony框架使用私钥加密。它适用于非二进制文件,但不适用于二进制文件。

$gestor = fopen($file, "rb");
$data = fread($gestor, filesize($file));
fclose($gestor);


$fp=fopen("cert.key","r");
$priv_key=fread($fp,8192);
fclose($fp);

$res = openssl_get_privatekey($priv_key);

$crypttext="";
$response = openssl_private_encrypt($data,$crypttext,$res);
//$response is false and $crypttext is empty

$sign_file = fopen($tsrfile.".sign", "wb") or die("Unable to open file!");
fwrite($sign_file, $crypttext);
fclose($sign_file); 

0 个答案:

没有答案