Affordable stylish trousers and shirts |
IntroductionThe 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. This document is a good introduction to hashes News: An alpha release is available for the next version of the MD5 and SHA1 scripts. They now support utf-8 input encoding and output in any arbitrary encoding. Also, the information about writing a login system has been much expanded, although the online example is not currently working. Demonstrationhex_md4("test hash") = "549089516e75bd13c41ff098fbb58d5e" hex_md5("message digest") = "f96b697d7cb7938d525a2f31aaf161d0" hex_sha1("160-bit hash") = "90d925d853c3d35cd54070bb75280fefad9de9e7" The Scripts
Quick instructionsFirst download the appropriate files from the links above. Save them in the same directory as your html file and insert a tag like: <script type="text/javascript" src="md5.js"></script> When you want to calculate a hash, use: <script type="text/javascript"> hash = hex_md5("input string"); </script> or md4/sha1 appropriately. These functions return the hash in hexadecimal. The library can also generate HMACs for all three algorithms. Also, Alejandro Gervasio has written a great set of articles walking you through creating a login system. See parts one, two and three. Recently Discovered WeaknessesSome weaknesses have recently been discovered in the MD5 and SHA-1 algorithms (more information). The hashes are designed so it is very difficult to find two messages that produce the same hash, this is called "collision resistance". Because MD5 is 128-bit, by random chance you will find a collision by producing 264 hashes. The weakness in MD5 is that a way has been found to produce such collisions with only 242 hashes. This makes producing collisions practical and I have seen an example of 100 different collisons. The use of MD5 or SHA-1 for most JavaScript purposes (e.g. challenge-response login) does not rely on the collision resistance property. These weaknesses do not create any vulnerability in such web sites and there is no need to panic. If these weaknesses do concern you, there are alternative algorithms available: Uses of hashes
Limitations of JavaScript CryptographyOver 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. Here is some information on benchmarking the hash functions. Users of my Script
Hash code in other languages
More JavaScript CryptographyThere is a lot of low-grade JS crypto about, but these links are all to relatively high-grade algorithms:
© 1998 - 2008 Paul Johnston, distributed under the BSD License Updated:10 Aug 2008 |