The pkcs7 encryption in python seems to be implemented differently, and the results are completely different. The php code is as follows {code...}. How should I write this method using python?
The pkcs7 encryption in python seems to have different implementations, and the results are completely different.
The php code 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"; // Save the signed base64 File $ signedDataFile = ". /rsa /". $ Millisecond. "signedData.txt"; // Save the envelope File $ envelopeFile = ". /rsa /". $ Millisecond. "envelope.txt"; # Load p12 openssl_pkcs12_read (file_get_contents (Contants: pri), $ certs, Contants: passWord); $ signCert = $ certs ['cert']; $ signKey = $ certs ['pkey']; # load the encryption certificate $ encryCert = file_get_contents (Contants: pub); # encrypt the original text $ fp = fopen ($ dataFile, "w"); fwrite ($ fp, $ data); fclose ($ fp); # sign openssl_pkcs7_sign ($ dataFile, $ signedFile, $ signCert, array ($ signKey, ""), NULL, bytes | PKCS7_BINARY | bytes); $ signedBase64 = bytes ($ 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 ); # envelope encryption ($ signedDataFile, $ envelopeFile, $ encryCert, NULL, PKCS7_BINARY, encoding); $ encryption = encoding ($ envelopeFile); $ envelopeBase64 = substr ($ envelopeBase64, strpos ($ envelopeBase64, "base64") + strlen ("base64"); trim ($ envelopeBase64); $ envelopeBase64 = base64_decode ($ envelopeBase64 ); $ response = base64_encode ($ envelopeBase64); // $ envelopeBase64 = str_replace ("\ r \ n", "", $ envelopeBase64); // print_r ($ envelopeBase64 ); // Delete the unlink ($ dataFile) file created during encryption; unlink ($ signedFile); unlink ($ signedDataFile); unlink ($ envelopeFile); return $ envelopeBase64;
}
How should I write this method in python?
Reply content:
The pkcs7 encryption in python seems to have different implementations, and the results are completely different.
The php code 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"; // Save the signed base64 File $ signedDataFile = ". /rsa /". $ Millisecond. "signedData.txt"; // Save the envelope File $ envelopeFile = ". /rsa /". $ Millisecond. "envelope.txt"; # Load p12 openssl_pkcs12_read (file_get_contents (Contants: pri), $ certs, Contants: passWord); $ signCert = $ certs ['cert']; $ signKey = $ certs ['pkey']; # load the encryption certificate $ encryCert = file_get_contents (Contants: pub); # encrypt the original text $ fp = fopen ($ dataFile, "w"); fwrite ($ fp, $ data); fclose ($ fp); # sign openssl_pkcs7_sign ($ dataFile, $ signedFile, $ signCert, array ($ signKey, ""), NULL, bytes | PKCS7_BINARY | bytes); $ signedBase64 = bytes ($ 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 ); # envelope encryption ($ signedDataFile, $ envelopeFile, $ encryCert, NULL, PKCS7_BINARY, encoding); $ encryption = encoding ($ envelopeFile); $ envelopeBase64 = substr ($ envelopeBase64, strpos ($ envelopeBase64, "base64") + strlen ("base64"); trim ($ envelopeBase64); $ envelopeBase64 = base64_decode ($ envelopeBase64 ); $ response = base64_encode ($ envelopeBase64); // $ envelopeBase64 = str_replace ("\ r \ n", "", $ envelopeBase64); // print_r ($ envelopeBase64 ); // Delete the unlink ($ dataFile) file created during encryption; unlink ($ signedFile); unlink ($ signedDataFile); unlink ($ envelopeFile); return $ envelopeBase64;
}
How should I write this method in python?
Do you need someone to help you rewrite the code or this: http://www.php2python.com /?
You just need to rewrite it. You cannot find it.