2017-12-18 151 views
0

我正在学习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)); 
+0

这可能帮助你.. https://gist.github.com/thinkphp/5110833 –

+0

为了完整起见,请注意,SHA-1应该不再被认为是安全的用于加密的目的。使用其他哈希函数,如SHA-2系列。 – YSK

回答

0

Node.js为您提供crypto模块。

const crypto = require('crypto'); 
crypto.createHash('sha1').update(stringToSign).digest('base64');