【问题标题】:How to create a HMAC-SHA1 hash in Nestjs如何在 Nestjs 中创建 HMAC-SHA1 哈希
【发布时间】:2020-06-01 19:46:34
【问题描述】:

我在我的 nestjs 应用程序中使用了一个 API。我需要提供哈希作为有效负载的一部分。

在 API 文档中,我应该这样做

使用 hash_hmac 函数创建哈希

computed_hash = hash_hmac("sha1", somecombinedstring, privatekey)

所以我在nodejs中使用了cryptojs

var hash = crypto.createHmac('sha1', combinestring, privatekey);

当我将哈希传递给端点时,我得到 Invalid Hash

如何创建有效的哈希

谢谢

【问题讨论】:

    标签: node.js hash nestjs hmac


    【解决方案1】:

    我可以使用它

      const hash = crypto.createHmac('sha1', privatekey)
                .update(somestringcombined)
                .digest('hex');
    

    【讨论】:

      猜你喜欢
      • 2011-11-20
      • 2020-03-04
      • 2010-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-26
      相关资源
      最近更新 更多