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);key.clamp(); -js/hmac.js:58:18有加密,我不确定什么是最好的方法。我尝试使用HmacSHA512,但它返回相同的错误。
我使用的是npm 6.1.0 node v6.10.3 crypto-js ^3.1.9-1。
发布于 2018-07-09 15:44:16
在their samples中,secret (或者他们称之为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);https://stackoverflow.com/questions/51239747
复制相似问题