What is Hashing? What is the Purpose of Hashing?

Let’s say you need to copy a file from one computer to another. How would you ensure that the two files (original and copy) are the same? You can use hashing to do this.

What is Hashing?

But what is hashing and how it works exactly?

A hashing algorithm transforms blocks of data that a file consists of into shorter values of fixed length. In other words, a hash value is basically a summary of what is in that file.

How does this work?

Data is stored in hash tables as key and value pairs. Each hash table has 3 basic operations it can do:

  1. Insert – to insert a specific value in the hash table;
  2. Delete – to delete a specific value in the hash table;
  3. Search – to insert a specific value in the hash table.

A hash key itself is an integer to which a hash function is applied and is used as an address of the hash table. In other words, a hash function maps hash keys to locations (indexes in the table).

However, if more than one hash key maps to the same index, this is called a “hash collision”. What this means is that a hash algorithm could produce the same hash value using two different outputs, which we don’t want. What a good hash algorithm does is that it offers as little collision chance as possible.

Most Common Types of Hashing

A hash algorithm can come in several types, the three most common being:

  1. SHA-2

SHA-2 followed SHA-1, but introduced many new changes. It has six hash functions with hash values of 224, 254, 384 and 512 bits(SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256). This type of hashing was developed by the NSA.

  1. CRC32

The cyclic redundancy check is typically used to check for file integrity in FTP servers and Zip files. It’s an error-detecting code that looks for accidental data changes.

  1. MD5

MD5 is an older type of hashing, which encodes information into a 128-bit fingerprint and is usually used to verify data integrity (as a checksum). However, it is very vulnerable to hash collisions.

  1. BCrypt

This type of hash function is admittedly slower but that’s because it is intended to thwart hackers from cracking passwords by making it more time-consuming and make sure they can’t execute quick attacks.

  1. xxHash

This hash function works best with small data and its main advantage lies in great speeds compared to other hash functions.

  1. RipeMD

RipeMD is used in the Bitcoin standard (and is used by other cryptocurrencies as well). It is usually available in a 160-bit configuration, but in other multiple-bit configurations as well.

What are the Pros and Cons of Hashing?

Of course, just as hashing has its advantages, it also has its disadvantages. Let’s take a look at the pros and cons of hashing next.

Hashing pros:

Hashing cons:

What is Salting? How is a Password Salted and Hashed?

You probably heard the term “salted and hashed”. What does this mean? How is a password “salted”?

Salting is a practice of combining each stored password with a randomly generated string of characters first before hashing the results. This string is called a “salt”.

Each user and password will have a unique salt, stored with the hash.

What does salting do?

Salting servers two main purposes in protecting stored passwords.

The first one is that salting prevents certain types of cyberattacks from being executed, or makes them very difficult.

Also, since there’s a high possibility of finding two identical passwords in the database, used by two different users, since the server will generate different salts for each, their resulting hash won’t match.

Hashing vs Encryption Differences

At first glance, hashing does the same thing as encryption, which is to scramble the data so that it becomes unreadable to anyone without the proper key or way to decipher it.

However, there are actually quite a few differences between hashing vs encryption.

One of the biggest differences is that hashing works only one-way, which makes the hashing function irreversible. Encryption, on the other hand, is a two-way process, which makes it reversible.

The purpose of the two, is therefore different as well.

Hashing is used to convert input data into an output hash. This hash has a fixed-length string of characters, called a “hash value” or simply “hash”.

Encryption is used to convert normal text into a ciphertext, which can only be deciphered using a decryption key. This is usually done with either one key that is used to both encrypt and decrypt the message, as in the case of symmetric encryption, or with one key (public) to encrypt) and another to decrypt (private), as in asymmetric encryption.

Here are the differences:

Type:

Function:

Result:

Algorithm types:

Output:

So which one is better? Hashing vs encryption?

It depends on the purpose.

For instance, if you need to store passwords in a database, hashing is a better option for the fact that, in the event of a breach, a hacker won’t be able to access the passwords in plaintext and find out the passwords.

Of course, neither is perfect and a mix of hashing and encryption is usually the best to protect an organization and its data.

For instance, when you sign up to CTemplar, the RSA private and public keys are generated using your password as the private key passphrase and stored on the CTemplar server. The keys are then retrieved with a successful user login and the password never gets sent to the server in its plaintext form.

Instead, the password is hashed with the salt from your username and can’t be used to find out the actual password you made. This way, only you will know the actual password that you will need to decrypt an email. Not even CTemplar will be able to see your password. The hash is irreversible.

For those exploring the intricacies of various hashing algorithms and their impact on cryptocurrency security and efficiency, it’s essential to consider the practical tools that assist in managing these digital assets.

One such invaluable resource is the Dogecoin calculator, which offers users a straightforward way to calculate the conversion rates between Dogecoin and other currencies, making it easier to understand the real-time value of your Dogecoin holdings.

Whether you’re a seasoned investor or new to the world of cryptocurrencies, this calculator is a must-have tool for making informed decisions in the dynamic landscape of digital currency.

You can read more about how CTemplar manages your passwords and generates keys in our whitepaper.

What is consistent hashing?

Consistent hashing is a strategy used in systems with large distributed databases, where it becomes necessary to divide the data between many computers. This works independently of the number of servers and/or objects in a distributed hash table by assigning each a position in a hash ring, allowing the servers and object to scale.

What is salt in hashing?

Salt is a random data value added to the password (usually at the end) to produce a different hash value and add extra security against brute force attacks.

Difference between hashing and encryption?

Hashing is a one-way process and there is no key that will convert the input to its original value. Encryption is a two-way process that uses keys to change text into ciphertext and back.

What type of encryption algorithm uses two keys to encrypt?

Asymmetric encryption uses a public key to encrypt data and a private key to decrypt it.

What is double hashing?

Double hashing is a collision-resolving technique used in Open Addressed hash tables and is an idea of using an additional hash function to the hash key in the event of a collision.

Conclusion

Both hashing and encryption have their important place in cryptography and data security, especially when it comes to password management.

Hashing, for instance, is a way to go if you are worried that a file you want to send to someone might be intercepted and changed by a 3rd-party.

On the other hand, encryption is best used if you need to send a message (like an email message) and ensure that only the right recipient will be able to read it.

At CTemplar, we protect your passwords and other data with both encryption (Open PGP, 4096-bit) and hashing algorithm (we use BCrypt for hashing passwords).