admin管理员组文章数量:1325380
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?
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?
Share Improve this question asked Mar 9, 2012 at 17:51 XeoncrossXeoncross 57.3k83 gold badges271 silver badges371 bronze badges 2- 3 There exist many. Google is your friend. (Example: webtoolkit.info/javascript-sha1.html ) – user1150525 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. – Tim M. Commented Mar 9, 2012 at 18:14
3 Answers
Reset to default 6I 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./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.
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
- http://www.movable-type.co.uk/scripts/sha1.html
- http://www.webtoolkit.info/javascript-sha1.html
- http://jssha.sourceforge/
MD5 (with some others included)
- http://pajhome.uk/crypt/md5/
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.
本文标签: What hash algorithms are supported by modern JavascriptStack Overflow
版权声明:本文标题:What hash algorithms are supported by modern Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742192113a2430404.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论