linux - python复写php的代码
程序员文章站
2022-06-17 08:41:45
...
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/ ?
就是重写下啦,搜不到
上一篇: MySQL使用DNS的过程
下一篇: 字符串
推荐阅读
-
PHP读取PDF内容(LINUX下XPDF的配置和使用)_PHP教程
-
php升级 - 正在运行中的服务器,如何平滑从php5.2升级到php5.3 ,linux+php-fpm+nginx
-
Linux和Windows平台下PHP中PDF支持库的安装及应用案例_PHP
-
python的分布式任务huey如何实现异步化任务讲解_PHP教程
-
PHP获取变量的变量名的一段代码的bug_PHP教程
-
【精品推荐】高质量PHP代码的50个实用技巧
-
php中生成随机密码的自定义函数代码
-
python实现语音常用度量方法的代码详解
-
PHP var_dump遍历对象属性的函数与应用代码
-
完善CodeIgniter在IDE中代码提示功能的方法_PHP