Node.js crypto module encryption algorithm

background

When the WeChat applet calls the Moth thermal paper printer, parameter sig signature verification is required, and SHA1 is used for encryption.

// 通过crypto.createHash()函数,创建一个hash实例,但是需要调用md5,sha1,sha256,sha512算法来实现实例的创建。

// 创建hash实例
crypto.createHash();

// 生成一个sha1算法的hash实例
let sha1 = crypto.createHash('sha1');

// 指定要摘要的原始内容,可以在摘要被输出之前使用多次update方法来添加摘要内容
let sha1Sum = sha1.update('hello world');

// 摘要输出16进制。因为它默认返回的是2进制的数据,然后我们接着 
let result = sha1Sum.digest('hex');

// 期望以16进制的形式打印md5值 (在使用digest方法之后不能再向hash对象追加摘要内容) 
sha1Sum.digest(‘hex’); 

console.log(result)

おすすめ

転載: blog.csdn.net/u013302168/article/details/132570154