微信小程序调用飞蛾热敏纸打印机,需要进行参数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)
