![]()
The MD4, MD5 and SHA-1 algorithms are secure hash functions. They take a string input, and produce a fixed size number - 128 bits for MD4 and MD5; 160 bits for SHA-1. This number is a hash of the input - a small change in the input results in a substantial change in the output. The functions are thought to be secure, in the sense that it would require an enormous amount of computing power to find a string which hashes to a chosen value. In others words, there's no way to decrypt a secure hash. The uses of secure hashes include digital signatures and challenge hash authentication.
First download the appropriate files from the links above. Save them in the same directory as your html file and insert a tag like:
When you want to calculate a hash, use:
or md4/sha1 appropriately. These functions return the hash in hexadecimal.
The library can also generate HMACs
for all three algorithms.
Over the web, JS cryptography can only protect against passive eavesdropping, as the JavaScript itself is downloaded over an insecure link. If an attacker can modify network traffic, they can make malicious changes to the JavaScript code. In any case, JS interpreters are not designed for secure programming. They may leave sensitive information lying about in memory. They're too slow for some algorithms, e.g. BSD-style MD5 passwords, or RSA with full-size keys. Bitwise operations are buggy in several implementations.
There is a lot of low-grade JS crypto about, but these links are all to relatively high-grade algorithms:
© 1998 - 2003 Paul Johnston, distributed under the BSD License Updated: 27 Jul 2003 |