我使用Java2c2p(https://developer.2c2p.com/docs/status-inquiry) API,但他们使用的是PHP语言,我不知道如何在Java语言中实现PHP语言的openssl_pkcs7_encrypt方法
我搜索了node.js(PKCS7 encrypt decrypt in Node.js)的实现,但没有找到
这是由2c2p提供的PHP代码示例
function encrypt($text,$publickey)
{
//write text to file
if(!file_exists( dirname(__FILE__)."/tmp/"))
{
mkdir( dirname(__FILE__)."/tmp/");
}
$filename = dirname(__FILE__)."/tmp/".time().".txt";
$this->text_to_file($text,$filename);
$filename_enc = dirname(__FILE__)."/tmp/".time().".enc";
$key = file_get_contents($publickey);
if (openssl_pkcs7_encrypt($filename, $filename_enc, $key,
array())) {
// message encrypted - send it!
unlink($filename);
if (!$handle = fopen($filename_enc, 'r')) {
echo "Cannot open file ($filename_enc)";
exit;
}
$contents = fread($handle, filesize($filename_enc));
fclose($handle);
$contents = str_replace("MIME-Version: 1.0
Content-Disposition: attachment; filename=\"smime.p7m\"
Content-Type: application/pkcs7-mime; smime-type=enveloped- data; name=\"smime.p7m\"
Content-Transfer-Encoding: base64
","",$contents);
$contents = str_replace("\n","",$contents);
unlink($filename_enc);
return $contents;
}
}发布于 2020-05-20 14:34:28
您好,您可以从此链接https://support.2c2p.com/attachments/token/OaGZTrZWkqVMlHlhhpo3pBT2Y/?name=JAVA.rar下载使用pkcs7加密和解密的2c2p状态查询的完整代码
https://stackoverflow.com/questions/57263676
复制相似问题