3

I would like to generate SHA1 or similar hashes using only client-side Javascript. In other words, using the Javascript engines provided with IE, FF, and Webkit. I am wondering what hash implementations exist?

2
  • 3
    There exist many. Google is your friend. (Example: webtoolkit.info/javascript-sha1.html ) Commented Mar 9, 2012 at 17:53
  • 3
    @user1150525 - I think the OP is looking for an implementation using only the JS engine in the browser. I was just searching for the same thing myself last night to avoid a dependency on a third party library. Commented Mar 9, 2012 at 18:14

3 Answers 3

6

I don't believe there are any built directly into the browser, but there are some well-documented implementations.

The best I have found is http://code.google.com/p/crypto-js/ which is available via CDN and supports:

  • MD5
  • SHA-1
  • SHA-256
  • AES
  • DES
  • Rabbit
  • MARC4
  • HMAC
  • HMAC-MD5
  • HMAC-SHA1
  • HMAC-SHA256
  • PBKDF2

If security matters then use an algorithm that hasn't been broken (yet) and is less subject to various forms of attack (wikipedia has a nice breakdown at the bottom of this article).

Based on the lack of answers to this question, it doesn't seem like this is native browser functionality. I wish there was, but I could see issues arising from relying on the browser. For example, if a flaw was discovered in an algorithm, it would be difficult to move your users to a new algorithm until you knew all of their browsers supported it (and they had upgraded). If you control the hashing algorithm, then you can deploy a new script whenever you wish.

Sign up to request clarification or add additional context in comments.

Comments

3

I'm not sure about built-in hash implementations other than what's already used for associative arrays, but here are some sample implementations with code.

SHA

MD5 (with some others included)

1 Comment

I also found Mootool's version and this gist.
0

Movable Type has published a js implementation of SHA1 here: http://www.movable-type.co.uk/scripts/sha1.html

I'm sure there are plenty of other implementations.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.