2016-10-05 1 views
-1

을주고있다 :자바 스크립트 : SHELL의 shasum 및 JS 라이브러리의 암호화는 여기에 유닉스 나에게 제공하고 올바른 무슨 다른 결과

자바 스크립트에서
shasum -a 256 test.jpg 
df94ac3fd72415827f345b5fa22761f57d87e99c25d5345d2e8e9f6c91ef34a3 test.jpg 

, 내가 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')); 
} 

결과는 다음과 같습니다 shasum 명령 행에서 같은 df94ac3fd72415827f345b5fa22761f57d87e99c25d5345d2e8e9f6c91ef34a3를 얻을

da5698be17b9b46962335799779fbeca8ce5d491c0e26243bafef9ea1837a9d8 
6e340b9cffb37a989ca54ee6bb780a2c78901d3fb33738768511a30617afa01d 
7ce85f64d69c7a8865413deaff3d65ca0272dfbe74ad9bc07s5e28679243cb69 
da5698be17b9b46962335799779fbeca8ce5d491csd26243bafef9ea1837a9d8 

수 없습니다. 내가해야 할 일이 무엇인지 말씀해 주시겠습니까 sha?

+0

파일 내용이 아니라 파일 이름의 요약을 처리하면됩니다. 그래서 그들은 다를 것입니다. – Keith

+0

파일 내용을 어떻게 처리 할 수 ​​있습니까? @Keith –

+1

여기를 보면 파일 내용을 볼 수 있습니다. -> https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data – Keith

답변

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); 

감사합니다, 키스.

관련 문제