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

后端 未结 4 1761
不思量自难忘°
不思量自难忘° 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 09:52

    You may want to take a look at the Stanford JS Crypto Library

    GitHub

    Website with Examples

    From the website:

    SJCL is secure. It uses the industry-standard AES algorithm at 128, 192 or 256 bits; the SHA256 hash function; the HMAC authentication code; the PBKDF2 password strengthener; and the CCM and OCB authenticated-encryption modes.

    SJCL has a test page that shows how long it will take.

    184 milliseconds for a SHA256 iterative. And 50 milliseconds for a SHA-256 from catameringue.

    Test page

    Sample code:

    Encrypt data: sjcl.encrypt("password", "data")

    Decrypt data: sjcl.decrypt("password", "encrypted-data")

提交回复
热议问题