【发布时间】:2020-02-10 18:10:25
【问题描述】:
我正在为 node js 13.6.0 和 express 3 使用 twig js 模板。
我正在尝试将我的 php 网站转换为节点 js。在 php 中,我使用 OpenSSL 加密/解密用户信息 现在我想在节点 js 中做同样的事情。
php函数
$secure_key= "Wzm7phmY8SwjtInXk1nY";//
$cipher = "AES-128-ECB";
function encrypt($pure_string, $encryption_key) {
global $cipher;
$encrypted_string = openssl_encrypt($pure_string, $cipher, $encryption_key);
return $encrypted_string;
}
function decrypt($encrypted_string, $encryption_key) {
global $cipher;
$decrypted_string = openssl_decrypt($encrypted_string, $cipher, $encryption_key);
return $decrypted_string;
}
我想做完全相同的功能,但对于 node.js
如果你有任何想法请回答
【问题讨论】:
-
Node 等效项可以是
crypto.createCipher('aes-128-ecb', key)。问题是您的密钥与 128 位密钥大小不匹配,我不知道 createCipher() 如何处理更长的密钥。此外,createCipher() 已被弃用,ECB 也不是那么安全。如果我是你,我会解密所有内容,然后使用更强大的密码对其进行加密。
标签: javascript node.js encryption openssl