十六进制值的散列函数不是crypto-js中的字符串

时间:2018-01-17 16:56:21

标签: javascript sha256 hash-function

假设我需要将0xF0FD93的SHA-256哈希值作为十六进制值而不是字符串。

var SHA256 = require('crypto-js/sha256');
hash = SHA256(0xF0FD93);
console.log(hash.toString()); //4ea5c508a6566e76240543f8feb06fd457777be39549c4016436afda65d2330e

根据这个http://extranet.cryptomathic.com/hashcalc/index,我应该得到 a2ad9b3ba41abb6e4e4cafa6467efe65f58f0fb9a01b0f96c6548188ded27356

编辑我解决了它:

var CryptoJS = require('crypto-js')

var message = CryptoJS.enc.Hex.parse('F0FD93');
var hash = CryptoJS.SHA256(message);
console.log(hash.toString()); // a2ad9b3ba41abb6e4e4cafa6467efe65f58f0fb9a01b0f96c6548188ded27356

var wrongMessage = ('F0FD93');
var wrongHash = CryptoJS.SHA256(wrongMessage);

console.log(wrongHash.toString()); //c55b21323979adf4f963998e272827739a86ddeb8afc85b4e5dea3cdef7274be

0 个答案:

没有答案