python里面的pkcs7加密好像实现不一样,得出的结果完全不一样
php的代码如下
public static function envelope($data){ $millisecond = signenvelope::getmillisecond(); //保存源数据文件 $datafile = ./rsa/.$millisecond.data.txt; //保存签名文件 $signedfile = ./rsa/.$millisecond.signed.txt; //保存签名后base64文件 $signeddatafile = ./rsa/.$millisecond.signeddata.txt; //保存信封后文件 $envelopefile = ./rsa/.$millisecond.envelope.txt; #加载p12 openssl_pkcs12_read (file_get_contents(contants::pri), $certs, contants::password); $signcert = $certs ['cert']; $signkey = $certs['pkey']; #加载加密证书 $encrycert = file_get_contents(contants::pub); #加密原文 $fp = fopen($datafile, w); fwrite($fp, $data); fclose($fp); #签名 openssl_pkcs7_sign($datafile,$signedfile, $signcert, array($signkey,), null, pkcs7_noattr|pkcs7_binary|pkcs7_nosigs); $signedbase64 = file_get_contents($signedfile); $signedbase64 = substr($signedbase64, strpos($signedbase64, base64) + strlen(base64)); trim($signedbase64); #print_r($signedbase64); #echo
; $signeddata = base64_decode($signedbase64); $fp = fopen($signeddatafile, w); fwrite($fp, $signeddata); fclose($fp); #信封 openssl_pkcs7_encrypt($signeddatafile,$envelopefile, $encrycert, null, pkcs7_binary, openssl_cipher_3des); $envelopebase64 = file_get_contents($envelopefile); $envelopebase64 = substr($envelopebase64, strpos($envelopebase64, base64) + strlen(base64)); trim($envelopebase64); $envelopebase64 = base64_decode($envelopebase64); $envelopebase64 = base64_encode($envelopebase64); //$envelopebase64 = str_replace(\r\n,,$envelopebase64); //print_r( $envelopebase64 ); //删除加密过程中创建的文件 unlink($datafile); unlink($signedfile); unlink($signeddatafile); unlink($envelopefile); return $envelopebase64;
}
如果要用python实现这个方法的话,应该怎么写?
回复内容: python里面的pkcs7加密好像实现不一样,得出的结果完全不一样
php的代码如下
public static function envelope($data){ $millisecond = signenvelope::getmillisecond(); //保存源数据文件 $datafile = ./rsa/.$millisecond.data.txt; //保存签名文件 $signedfile = ./rsa/.$millisecond.signed.txt; //保存签名后base64文件 $signeddatafile = ./rsa/.$millisecond.signeddata.txt; //保存信封后文件 $envelopefile = ./rsa/.$millisecond.envelope.txt; #加载p12 openssl_pkcs12_read (file_get_contents(contants::pri), $certs, contants::password); $signcert = $certs ['cert']; $signkey = $certs['pkey']; #加载加密证书 $encrycert = file_get_contents(contants::pub); #加密原文 $fp = fopen($datafile, w); fwrite($fp, $data); fclose($fp); #签名 openssl_pkcs7_sign($datafile,$signedfile, $signcert, array($signkey,), null, pkcs7_noattr|pkcs7_binary|pkcs7_nosigs); $signedbase64 = file_get_contents($signedfile); $signedbase64 = substr($signedbase64, strpos($signedbase64, base64) + strlen(base64)); trim($signedbase64); #print_r($signedbase64); #echo
; $signeddata = base64_decode($signedbase64); $fp = fopen($signeddatafile, w); fwrite($fp, $signeddata); fclose($fp); #信封 openssl_pkcs7_encrypt($signeddatafile,$envelopefile, $encrycert, null, pkcs7_binary, openssl_cipher_3des); $envelopebase64 = file_get_contents($envelopefile); $envelopebase64 = substr($envelopebase64, strpos($envelopebase64, base64) + strlen(base64)); trim($envelopebase64); $envelopebase64 = base64_decode($envelopebase64); $envelopebase64 = base64_encode($envelopebase64); //$envelopebase64 = str_replace(\r\n,,$envelopebase64); //print_r( $envelopebase64 ); //删除加密过程中创建的文件 unlink($datafile); unlink($signedfile); unlink($signeddatafile); unlink($envelopefile); return $envelopebase64;
}
如果要用python实现这个方法的话,应该怎么写?
你需要别人帮你重写代码还是这个:http://www.php2python.com/ ?
就是重写下啦,搜不到