Python's PKCS7 encryption seems to be different, and the results are completely different.
The code for PHP is as follows
public static function Envelope ($data) {$Millisecond = Signenvelope::getmillisecond (); Save the source data file $dataFile = "./rsa/". $Millisecond. " Data.txt "; Save the signature file $signedFile = "./rsa/". $Millisecond. " Signed.txt "; After saving the signature base64 file $signedDataFile = "./rsa/". $Millisecond. " SignedData.txt "; File $envelopeFile = "./rsa/" after saving the envelope. $Millisecond. " Envelope.txt "; #加载p12 Openssl_pkcs12_read (file_get_contents (contants::p ri), $certs, contants::p assword); $signCert = $certs [' cert ']; $signKey = $certs [' Pkey ']; #加载加密证书 $encryCert = file_get_contents (contants::p UB); #加密原文 $fp = fopen ($dataFile, "w"); Fwrite ($fp, $data); Fclose ($FP); #签名 openssl_pkcs7_sign ($dataFile, $signedFile, $signCert, Array ($signKey, ""), NULL, pkcs7_noattr| pkcs7_binary| Pkcs7_nosigs); $signedBase = file_get_contents ($signedFile); $signedBase = substr ($signedBase, Strpos ($signedBase, "base64") + strlen ("base64")); Trim ($signedBase 64); #print_r ($signedBase 64); #ecHo "
"; $signedData = Base64_decode ($signedBase 64); $fp = fopen ($signedDataFile, "w"); Fwrite ($fp, $signedData); Fclose ($FP); #信封 Openssl_pkcs7_encrypt ($signedDataFile, $envelopeFile, $encryCert, NULL, Pkcs7_binary, OPENS Sl_cipher_3des); $envelopeBase = file_get_contents ($envelopeFile); $envelopeBase = substr ($envelopeBase, Strpos ($envelopeBase, "base64") + strlen ("base64")); Trim ($envelopeBase 64); $envelopeBase = Base64_decode ($envelopeBase 64); $envelopeBase = Base64_encode ($envelopeBase 64); $envelopeBase = Str_replace ("\ r \ n", "", $envelopeBase 64); Print_r ($envelopeBase 64); Delete files created during encryption unlink ($dataFile); Unlink ($signedFile); Unlink ($signedDataFile); Unlink ($envelopeFile); return $envelopeBase 64;
}
What should I do if I want to implement this method in Python?
Reply content:
Python's PKCS7 encryption seems to be different, and the results are completely different.
The code for PHP is as follows
public static function Envelope ($data) {$Millisecond = Signenvelope::getmillisecond (); Save the source data file $dataFile = "./rsa/". $Millisecond. " Data.txt "; Save the signature file $signedFile = "./rsa/". $Millisecond. " Signed.txt "; After saving the signature base64 file $signedDataFile = "./rsa/". $Millisecond. " SignedData.txt "; File $envelopeFile = "./rsa/" after saving the envelope. $Millisecond. " Envelope.txt "; #加载p12 Openssl_pkcs12_read (file_get_contents (contants::p ri), $certs, contants::p assword); $signCert = $certs [' cert ']; $signKey = $certs [' Pkey ']; #加载加密证书 $encryCert = file_get_contents (contants::p UB); #加密原文 $fp = fopen ($dataFile, "w"); Fwrite ($fp, $data); Fclose ($FP); #签名 openssl_pkcs7_sign ($dataFile, $signedFile, $signCert, Array ($signKey, ""), NULL, pkcs7_noattr| pkcs7_binary| Pkcs7_nosigs); $signedBase = file_get_contents ($signedFile); $signedBase = substr ($signedBase, Strpos ($signedBase, "base64") + strlen ("base64")); Trim ($signedBase 64); #print_r ($signedBase 64); #ecHo "
"; $signedData = Base64_decode ($signedBase 64); $fp = fopen ($signedDataFile, "w"); Fwrite ($fp, $signedData); Fclose ($FP); #信封 Openssl_pkcs7_encrypt ($signedDataFile, $envelopeFile, $encryCert, NULL, Pkcs7_binary, OPENS Sl_cipher_3des); $envelopeBase = file_get_contents ($envelopeFile); $envelopeBase = substr ($envelopeBase, Strpos ($envelopeBase, "base64") + strlen ("base64")); Trim ($envelopeBase 64); $envelopeBase = Base64_decode ($envelopeBase 64); $envelopeBase = Base64_encode ($envelopeBase 64); $envelopeBase = Str_replace ("\ r \ n", "", $envelopeBase 64); Print_r ($envelopeBase 64); Delete files created during encryption unlink ($dataFile); Unlink ($signedFile); Unlink ($signedDataFile); Unlink ($envelopeFile); return $envelopeBase 64;
}
What should I do if I want to implement this method in Python?
Do you need someone to rewrite the code for you or this: http://www.php2python.com/?
It's just a rewrite, not a search.