我在当前项目中使用pkcs7加密解密。我想从PHP更改为Node.js. Node.js中是否有pkcs7加密/解密?在Node.js中PKCS7加密解密
在PHP中,
<?php
$data = <<<EOD
Hello world
EOD;
// load key
$key = file_get_contents("mypublickey.crt");
// save message to file
$fp = fopen("msg.txt", "w");
fwrite($fp, $data);
fclose($fp);
// encrypt it
if (openssl_pkcs7_encrypt("msg.txt", "enc.txt", $key,array())) {
// message encrypted - send it!
}
?>
解密
<?php
// The certification stuff
$public = file_get_contents("mypublickey.crt");
$private = array(file_get_contents("myprivatekey.pem"), "mypassword");
$infile = tempnam("", "enc");
file_put_contents($infile, $encrypted);
$outfile = tempnam("", "dec");
if(openssl_pkcs7_decrypt("enc.txt", "dec.txt", $public, $private))
{
// Decryption successful
echo file_get_contents("dec.txt");
}
?>
有没有像这样的Node.js任何类似的功能?
感谢PHP中pkcs7加密的简明示例:) – thomastiger
嘿!你有没有找到任何方法在Node.js中实现? – gokhanakkurt
没有运气。那为什么使用PHP进行项目。 – saturngod