加密NodeJs(SHA-1?)
问题描述:
我正在学习Node js
,我不知道如何使用Cryptography
库(SHA-1?)。如何在Node js
中使用SHA-1
。这里是伪代码:加密NodeJs(SHA-1?)
// Use a Base64-encoder that don't introduce line-breaks,
// or trim the output signature afterwards.
string signature = Base64.encode(SHA1.digest(stringToSign));
答
Node.js为您提供crypto模块。
const crypto = require('crypto');
crypto.createHash('sha1').update(stringToSign).digest('base64');
这可能帮助你.. https://gist.github.com/thinkphp/5110833 –
为了完整起见,请注意,SHA-1应该不再被认为是安全的用于加密的目的。使用其他哈希函数,如SHA-2系列。 – YSK