Cryptography Basics: Encryption and Hashing

Cryptography can be separated into major categories including Asymmetric Encryption, Symmetric Encryption and Hashes. The article explains the categories with related examples and screen captures.

Asymmetric and symmetric encryption

Asymmetric encryption

In terms of asymmetric encryption, different keys are used for encryption and decryption. The public key can be revealed to everyone. Therefore, it is also known as public-key cryptography. With the public key provided by a receiver, a sender can use it to encrypt a message. The encrypted message can only be decrypted via a private key owned by the receiver.

Advantages: Does not face the key exchange problem – no need to pass a shared secret to both parties.

Disadvantages: Much slower than symmetric encryption – only suitable for exchanging a small amount of data.

Examples: RSA, ECC, PKI (Public Key Infrastructure)

Use cases: Digital certificates issued by a certificate authority

ECC Encryption Example - Web Certificate
ECC Encryption Example – Web Certificate for noobquestions.com
RSA Encryption Example - Web Certificate
RSA Encryption Example – Web Certificate for bing.com

Symmetric encryption

As for symmetric encryption, the same key is used for encryption and decryption. A key is used to encrypt a message and the same key can be used to decrypt it. As a result, it is also known as shared key encryption.

Advantages: Much faster than asymmetric encryption – can be used to exchange a large amount of data.

Disadvantages: The key exchange problem – passing a shared secret to both parties can be difficult. There is no way to secure a communication during the initial key exchange stage. In other words, a message can be intercepted during the initial key exchange over an unsecure channel like the Internet.

Examples: AES

Use cases: File compress and decompress (ZIP), Streaming, Media Storage

AES Encryption Example - Compress File (ZIP)
AES Encryption Example – Compress File (ZIP)

Hashing

What is the difference between encryption and hashes?

Hashes is done one-way. If a message is hashed, it cannot be reversed. A unique hash is created for every message. In contrast, an encrypted message can be decrypted – the original content can be obtained if a message is encrypted rather than hashed.

Example: MD5, SHA

Use cases: File integrity check, password stored in a database and password comparison when logging in

Checksum Example
Checksum Example
b3bb91ad96f2d4c041861ce59ba6ac73  w64/putty.exe
Password Hash Example
Password Hash Example (OpenCast software, password stored in MariaDB, using bcrypt password hashing algorithm)