Node HmacSHA1 Seed

房东的猫 提交于 2019-12-02 09:58:35

I managed to get there in the end, there's an NPM module called psha1 (https://www.npmjs.com/package/psha1).

Using that library I created the following a generateSignature module which looks as follows:

const crypto = require('crypto');
const psha1 = require('psha1');

export const generateSignatureValue = ({
  clientSecret,
  serverSecret,
  messageToSign,
}) => {

  const secretKey =
    psha1(clientSecret, serverSecret, 256);

  const hash =
    crypto
      .createHmac('sha1', Buffer.from(secretKey, 'base64'))
      .update(messageToSign)
      .digest('binary');

  return Buffer
    .from(hash, 'binary')
    .toString('base64');
};

export default generateSignatureValue;

This gives me the desired output :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!