【发布时间】:2018-05-30 23:27:27
【问题描述】:
我有一些用于 API 的示例代码,但它是用 Ruby 编写的,而我更喜欢使用 nodeJS。各位好心的 ruby/JS 小伙子能否告诉我 JS 等价物是什么,以及我需要安装的任何 npm 库。
hmac = OpenSSL::HMAC.new(sharedsecret, OpenSSL::Digest::SHA512.new)
signature = hmac.update(url)
【问题讨论】:
我有一些用于 API 的示例代码,但它是用 Ruby 编写的,而我更喜欢使用 nodeJS。各位好心的 ruby/JS 小伙子能否告诉我 JS 等价物是什么,以及我需要安装的任何 npm 库。
hmac = OpenSSL::HMAC.new(sharedsecret, OpenSSL::Digest::SHA512.new)
signature = hmac.update(url)
【问题讨论】:
试试这个
var crypto = require('crypto');
hmac = crypto.createHmac('SHA512', sharedsecret);
hmac.update(url);
signature = hmac.digest('hex');
【讨论】: