What are Hashes?
Hashes are mathematical formulas that take a string of data of variable length, usually in the form of text, and convert it into shorter, fixed-length numeric values. Hashes are used frequently in computer databases in order to make searches faster and more efficient. They are also used in encryption to ensure that passwords are not compromised and to authenticate digital signatures, among other uses. Hashes also go by the name of hash functions, and can also be considered algorithms.
Hashes play a big role in facilitating database searches. In a database consisting of names, for example, if a user searches for “John Doe,” the computer would have to match up all of the characters in the search to those of every database entry. Every character in the name would have 26 different possibilities — the letters of the English alphabet — while the variable length of the entries would also slow down the search.
By contrast, applying a hash function would make the computer’s life much easier. Turning each text string into a series of numbers would simplify the search, because the computer would only have ten possibilities to check for each character: digits “0” to “9.” The fixed length of the number series also helps the computer do its job more efficiently.
In a database with a hash function applied, all entries have a corresponding, unique number. This is called a hash key. In this instance, when you make a search, the computer first applies the hash function to the input you’ve written, such as “John Doe.” This results in a numeric value, for example “456789.” The computer can then rapidly match this result to the hash key corresponding to the correct entry.
Hashes also function as digital signatures. For example, a sender, Robert, wants to send a document to someone and the recipient, Mary, wants to make sure the document hasn’t been tampered with while en route. The sender, Robert, only has to run the document through a hash function, which results in a numeric value. Robert then encrypts the hash key and sends the document along with the encrypted key.
Mary receives both items and decrypts the hash key. She can now see the numerical value that resulted from the document before it was sent. To verify that the document in her hands is the exact same one, she runs the document through a hash function on her computer. Lastly, she compares both keys. If they are the same, then the document wasn’t altered on its way to the recipient.
Many different hash functions exist, each with their own mathematical formulas. For a hash function to work, it must minimize any collision, which occurs when two database entries have the same hash key. Hash functions must also be one-way. That means you can produce a key from a database entry or document, but not the other way around. In other words, you cannot “reverse-engineer” the original document from its hash key.
Discuss this Article
Post your comments