SHA1 Embedding JavaScript for a Large String

I have the same problem as: Can the SHA-1 algorithm be computed by stream? With a low memory area?

I am looking for a JavaScript implementation that computes block by block of a very large string. The idea is to cut a string into 512 bit block and make it a block block.

Any clues?

[updated] Thanks sunetos help, I write litte html5 java script app: Generate a SHA1 checksum using the HTML5 API files in Javascript

+7
javascript hash sha1
source share
1 answer

I believe that I came across one of them by Paul Johnston at http://pajhome.org.uk/crypt/md5/contrib/sha1_stream.js . It is listed at http://pajhome.org.uk/crypt/md5/scripts.html . I did not test it myself, but I used its version without streaming, which he modified for it.

UPDATE: Here is a sample code (I tested it against a separate SHA1, which, as you know, was correct). Make sure you include the original sha1.js file (found at http://pajhome.org.uk/crypt/md5/sha1.js ) before the streaming sha1_stream.js.

<script src="sha1.js" type="text/javascript" charset="utf-8"></script> <script src="sha1_stream.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> var input = ''; var blocksize = 512; var h = naked_sha1_head(); for (var i = 0; i < input.length; i += blocksize) { var len = Math.min(blocksize, input.length - i); var block = input.substr(i, len); naked_sha1(str2binb(block), len*chrsz, h); } var result = binb2hex(naked_sha1_tail(h)); </script> 
+4
source share

All Articles