linux - python複寫php的代碼

來源:互聯網
上載者:User
  1. python裡面的pkcs7加密好像實現不一樣,得出的結果完全不一樣

  2. 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實現這個方法的話,應該怎麼寫?

回複內容:

  1. python裡面的pkcs7加密好像實現不一樣,得出的結果完全不一樣

  2. 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/ ?

就是重寫下啦,搜不到

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.