CryptoJS:key.clamp 不是函数

CryptoJS : key.clamp is not a function

TypeError: key.clamp is not a function
  at Object.init (path/node_modules/crypto-js/hmac.js:58:18)

当我尝试使用下面的相关代码在 Javascript 中创建 JWT 时出现上述错误。

const CryptoJS = require('crypto-js');
var hash = CryptoJS.HmacSHA256(token.join("."), secret);

crypto-js/hmac.js:58:18 有 key.clamp();,我不确定什么是最好的方法。我尝试使用 HmacSHA512 但它 returns 出现了同样的错误。

我是 运行 npm 6.1.0 node v6.10.3 crypto-js ^3.1.9-1.

来自 their samplessecret(或他们所说的 key),应该是 string

因此,像这样使用 CryptoJS 应该可以正常工作:

const token = "a,b"; // fake token
const secret = CryptoJS.enc.Utf8.parse("mySecret"); //encode mySecret into UTF-8 as suggested in the comments
const CryptoJS = require('crypto-js');
var hash = CryptoJS.HmacSHA256(token.split(","), secret);
console.log(hash);