DEV Community

Dita Larasati
Dita Larasati

Posted on • Updated on

Encode, Encrypt, and Hash

In general, the meaning of encode is to convert something into code, something into a different format. We usually do kind of encode for Personal Identifiable Information (PII) because it contains confidential data such as password, card number, etc.

Encoding

Simply said, encoding process happens as transforming a number from base 10 (decimal) into base 2 (binary) format. Usually, the algorithms used is in the form of rigid pattern such as conversion table of ASCII, Unicode, Base-64, and URL-encoding.

Encoding technique is reversible. Anyone who knows the algorithm could decode the encoded data in order to retrieve the original data.

Encryption

Similar to encoding, encryption technique is reversible but more secure. Encryption can protect data from unauthorized person. A key is also needed to encrypt and decrypt the data, not only the algorithm.

This key-based encryption algorithms is classified into symmetric-key algorithm and asymmetric-key algorithm. As the naming, the symmetric means that the key for encryption and decryption is equal, and the asymmetric is different. In asymmetric algorithm, public key is a name for the key to encrypt and private key is for to decrypt.

Below is an example functions to do encryption-decryption:
Image description

Hashing

On the other hand, hashing can not do that kind of decode. Hashing is irreversible and more secure than encryption. Once you hash something, you can not know what the "something" really is. Even though it literally hashes your data, I would say that you still could know what kind of thing the "something". Just imagine a criminal scene: you got potential suspects and blood of suspect in the crime scene. Here, the blood is the result of hash the potential suspect. By comparing the DNAs, we could know that the blood comes from the suspect.

Hashing usually is implemented for password. Although programmer who creates the program, programmer is not allowed to know user's password. A program must be designed to save user's password in the form of hashed password in database. None of way to decode it.

The following is example of hashing-comparing implementation:

hashing

comparing


References:

  1. https://auth0.com/blog/hashing-passwords-one-way-road-to-security/
  2. https://auth0.com/blog/encoding-encryption-hashing/

Top comments (0)