Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What hash algorithms are supported by modern Javascript?

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?

like image 251
Xeoncross Avatar asked Mar 19 '26 15:03

Xeoncross


1 Answers

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.

like image 171
Tim M. Avatar answered Mar 21 '26 06:03

Tim M.