Mid*_*ori 5 javascript jwt cryptojs
TypeError: key.clamp is not a function
at Object.init (path/node_modules/crypto-js/hmac.js:58:18)
Run Code Online (Sandbox Code Playgroud)
当我尝试使用下面的相关代码在Javascript中创建JWT时,会发生上述错误。
const CryptoJS = require('crypto-js');
var hash = CryptoJS.HmacSHA256(token.join("."), secret);
Run Code Online (Sandbox Code Playgroud)
crypto-js / hmac.js:58:18有key.clamp();,我不确定哪种方法最好。我尝试过,HmacSHA512但它返回相同的错误。
我正在跑步npm 6.1.0 node v6.10.3 crypto-js ^3.1.9-1。
从他们的样本来看,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);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3213 次 |
| 最近记录: |