Create SHA-256 hash from a Blob/File in javascript

后端 未结 4 1768
不思量自难忘°
不思量自难忘° 2021-02-02 09:20

I need to create a SHA-256 digest from a file (~6MB) inside the browser. The only way that I\'ve managed to do it so far was like this:

var reader = new FileRead         


        
4条回答
  •  无人共我
    2021-02-02 10:03

    This is an old question but I thought it's worth noting that asmCrypto is significantly faster than jsSHA, and faster than CryptoJS and SJCL

    https://github.com/vibornoff/asmcrypto.js/

    There is also a lite version (a fork of the above) maintained by OpenPGP.js

    https://github.com/openpgpjs/asmcrypto-lite

    Which only includes SHA256, and a couple of AES features.

    To use asmCrypto You can simply do the following:

    var sha256HexValue = asmCrypto.SHA256.hex(myArraybuffer);

    I'm able to hash a 150MB+ file in < 2 seconds consistently in Chrome.

提交回复
热议问题