这是Unix给我的东西,它是正确的:
shasum -a 256 test.jpg
df94ac3fd72415827f345b5fa22761f57d87e99c25d5345d2e8e9f6c91ef34a3 test.jpg
在Javascript中,我无法使用crypto-browserify
获取此内容。请看我的结果:
img.onload = function(e) {
console.log(crypto.createHash('sha256').update(e.path[0]).digest('hex'));
console.log(crypto.createHash('sha256').update(e.path).digest('hex'));
console.log(crypto.createHash('sha256').update(e.path[0].src).digest('hex'));
console.log(crypto.createHash('sha256').update(e).digest('hex'));
}
结果是:
da5698be17b9b46962335799779fbeca8ce5d491c0e26243bafef9ea1837a9d8
6e340b9cffb37a989ca54ee6bb780a2c78901d3fb33738768511a30617afa01d
7ce85f64d69c7a8865413deaff3d65ca0272dfbe74ad9bc07s5e28679243cb69
da5698be17b9b46962335799779fbeca8ce5d491csd26243bafef9ea1837a9d8
无法在df94ac3fd72415827f345b5fa22761f57d87e99c25d5345d2e8e9f6c91ef34a3
命令行中获得shasum
。你能告诉我该怎么办sha
?
答案 0 :(得分:0)
这就是我最终实施的方式:
var oReq = new XMLHttpRequest();
oReq.open("GET", "../test.jpg", true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent) {
var arrayBuffer = oReq.response;
if (arrayBuffer) {
var byteArray = new Uint8Array(arrayBuffer);
console.log(crypto.createHash('sha256').update(byteArray).digest('hex'));
}
};
oReq.send(null);
谢谢, 基思。