Xceed Encryption Library Documentation
Hash
Glossary topics > Hash

A hash function is a one-way function that converts a variable-length buffer or stream of data into a fixed-length value known as a hash value or message digest.

For example, a hash function can convert text of any length or binary data of any length into a 128-bit hash value that can be used as an encryption key. Because hash functions are one-way functions, the buffer or stream that was "hashed" cannot be recovered from the resulting message digest.

The best hash functions to use for encryption are those that render it computationally infeasible to attempt to find two different buffers or streams that convert to the same hash value. Examples of hash functions with this non-collision property are SHA-2 and HAVAL, both available in the Xceed Encryption Library.

Interesting uses for hash functions (other than for obtaining encryption keys) is to use them for password validation. It is not recommended to store a password, even encrypted, in a database. Well-designed systems usually store the hash value of the password instead. Thus, when a user logs in and enters their password, the password is hashed and compared with the stored hash value. If the hash values match, the password is valid. As stated above, the hash value cannot be used to recover the original password, and because of the non-collision property, it is infeasible to try passwords until you find one that hashes to the same hash value as the password does.