【问题标题】:Incorrect SHA256 from nodejs crypto来自 nodejs 加密的 SHA256 不正确
【发布时间】:2020-07-10 18:04:01
【问题描述】:
const crypto = require('crypto');

hm = crypto.createHmac("sha256","Some String");
console.log(hm.digest("base64"));

运行它给了我:

Nd6Q8epsIBG+c/jN6TdnfRNbFWCcB7bI0DYkfyDqf+8=

(repl)

但是在https://approsto.com/sha-generator/ 计算 sha256 给了我:

fw/WRlO6C7Glec7Str83XpFsxgZiEJ7gwLJPCnUMOmw

为什么会有差异?

【问题讨论】:

    标签: node.js sha256 hmac


    【解决方案1】:

    使用Hash 代替Hmac

    const crypto = require('crypto');
    
    hash = crypto.createHash("sha256");
    hash.update("Some String");
    console.log(hash.digest("base64"));
    

    结果:

    fw/WRlO6C7Glec7Str83XpFsxgZiEJ7gwLJPCnUMOmw=
    

    另见:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-04-14
      • 1970-01-01
      • 1970-01-01
      • 2019-08-19
      • 2019-02-20
      相关资源
      最近更新 更多