【发布时间】:2021-01-08 14:43:24
【问题描述】:
我有 2 段代码。
1ST ONE
const hash1 = (data) => createHash('sha256').update(data).digest('hex');
var a1 = hash1("A");
var b1 = hash1("B");
console.log(hash1(a1+b1));
2ND ONE
const hash2 = (data) => createHash('sha256').update(data).digest();
var a2 = hash2("A");
var b2 = hash2("B");
console.log(hash2(Buffer.concat([a2,b2])).toString('hex'));
他们为什么打印不同的结果?
digest('hex') 和digest() 相同,但格式不同,但仍然相同。那么,为什么我在控制台中得到不同的结果?当我总结十六进制而不是总结缓冲区时,它是 + 运算符吗?为什么?
【问题讨论】:
标签: javascript cryptography sha256 cryptojs