Javascript 找不到nodejs加密代码的浏览器js代码

Javascript 找不到nodejs加密代码的浏览器js代码,javascript,node.js,encryption,cryptography,cryptojs,Javascript,Node.js,Encryption,Cryptography,Cryptojs,我有一个基于当前时间戳生成签名的nodejs代码: var crypto = require('crypto'); var nonce = new Date().getTime(); var signature = function(nonce, secretKey) { var signature = crypto.createHmac('sha256', Buffer.from(secretKey, 'utf8')).update(Buffer.from(nonce, 'utf8')

我有一个基于当前时间戳生成签名的nodejs代码:

var crypto = require('crypto');
var nonce = new Date().getTime();
var signature = function(nonce, secretKey) {
    var signature = crypto.createHmac('sha256', Buffer.from(secretKey, 'utf8')).update(Buffer.from(nonce, 'utf8')).digest('base64');
    return signature;
}
我正在将此代码转换为浏览器js,但我的任务没有成功。 我参考了这个链接: 但没有起作用


如果
nonce=1518440585425
secret=9IeVABv94EQBnT6Mn73742kBZOmzFpsM+c62LU9b/h4=
它应该给出这个
signature=bli2ilr8mw4parkt4r1vvoxf42gjoavpgejt7ivo=
你的
节点的签名生成代码将等同于这个
crypto-js
代码:

var secret="9IeVABv94EQBnT6Mn73742kBZOmzFpsM+c62LU9b/h4=";
var nonce = "1518440585425";
var hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256,secret);
hmac.update(nonce);
var hash = hmac.finalize();
var signature = hash.toString(CryptoJS.enc.Base64);

console.log(signature); //blI2ILR8MW4ParkT4R1vvVOXF42gJOAVPgEJtZT7Ivo
您需要在HTML文件中包含以下js:

<script src="components/core.js"></script>
<script src="components/hmac.js"></script>
<script src="components/sha256.js"></script>
<script src="components/enc-base64.js"></script>