我在当前项目中使用 pkcs7 加密解密。我想从 PHP 更改为 Node.js。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 中是否有类似的功能?