我想使用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);