Encryption & Hashing

Encryption & Hashing

Encryption and hashing are two different methods of transforming data into a form that is unreadable to unauthorized parties. However, they have different purposes and characteristics.

– Encryption is the process of converting a normal readable message known as plaintext into a garbage message or not readable message known as ciphertext. The ciphertext obtained from the encryption can easily be transformed into plaintext using the encryption key. Encryption is a reversible process that allows the authorized users to access the original data by using the correct key and algorithm. Encryption is used to protect the confidentiality of data that needs to be stored or transmitted securely.

– Hashing is the process of converting the information into a key using a hash function. The original information cannot be retrieved from the hash key by any means. Generally, the hash keys are stored in the database and they are compared to check whether the original information matches or not. They are generally used to store the passwords for login. Hashing is an irreversible process that does not allow anyone to access the original data from the hash key. Hashing is used to verify the integrity and authenticity of data that needs to be validated.


Some of the main differences between encryption and hashing are:

  • – Encryption uses a key to encrypt and decrypt data, while hashing does not use any key.
  • – Encryption can be reversed to get back the original data, while hashing cannot be reversed to get back the original data.
  • – Encryption produces ciphertext of the same size or larger than the original data, while hashing produces a fixed-size hash value.
  • – Encryption can generate different ciphertexts for the same plaintext using different keys or algorithms, while hashing can generate only one hash value for the same input using the same hash function.
  • – Encryption is used for confidentiality, while hashing is used for integrity and authentication.

Can you provide some examples of Hashing and Encryption?

Sure, I can give you an example of encryption and hashing.

Let’s say you want to send a message to your friend Bob that says “Hello”. You don’t want anyone else to read your message, so you decide to encrypt it using a symmetric encryption algorithm called AES and a secret key that you and Bob share. You use an online tool to encrypt your message and get the following ciphertext:

U2FsdGVkX1+Qyf8Xy0t7wQ==

You send this ciphertext to Bob, who uses the same key and algorithm to decrypt it and get back your original message “Hello”.

Now let’s say you want to create an account on a website that requires a password. You don’t want anyone to know your password, so the website uses a hashing algorithm called SHA-256 to convert your password into a hash value. You choose the password “123456” and the website hashes it and gets the following hash value:

8d969eef6ecad3c29a3a629280e686cf8c32df9c9a48e94b1f59d0f0e9c5e9d8

The website stores this hash value in its database, but not your password. When you log in, the website hashes your password again and compares it with the stored hash value. If they match, you are authenticated. If not, you are denied access.

Note that encryption and hashing are not the same thing. Encryption can be reversed using the key, while hashing cannot be reversed at all. Encryption is used to protect data from unauthorized access, while hashing is used to verify data from unauthorized modification. Encryption can produce different outputs for the same input using different keys or algorithms, while hashing can produce only one output for the same input using the same algorithm.