背景

微信小程序调用飞蛾热敏纸打印机需要进行参数sig签名校验,使用的是sha1进行加密

// 通过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)

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注