Free tech learning for everyone, from basics to pro

Network SecurityNetworking SecurityIntermediate

Encryption and hashing: ciphers, symmetric and asymmetric keys, MD5, SHA and HMAC

In short: Encryption hides data by turning plaintext into ciphertext with an algorithm and a key. Symmetric algorithms such as AES use one shared key; asymmetric algorithms such as RSA and ECC use a public/private pair. Hash functions such as SHA-256 fingerprint data, and HMAC adds a secret key to prove authenticity.

Encryption basics

Encryption converts information into a secret code that hides its meaning. The science of encrypting and decrypting is cryptography. Unencrypted data is called plaintext; encrypted data is ciphertext; the formula used is the algorithm or cipher, and the secret value that controls it is the key.

Classic ciphers

  • Transposition: rearranges the order of letters without changing them. Example: writing a message in rows and reading it out by columns.
  • Substitution: replaces each letter with another. The Caesar cipher shifts every letter by a fixed amount (shift 3: A→D, so HELLO → KHOOR). The Vigenère cipher uses a keyword so the shift changes letter by letter.
  • One-time pad: combines the message with a truly random key as long as the message, used only once. Mathematically unbreakable, but impractical to distribute.

Classic ciphers are easily broken by computers today, but they show the two core ideas behind all modern algorithms: confusion and diffusion.

Symmetric and asymmetric encryption

Symmetric and asymmetric encryptionSymmetric: one shared keyAsymmetric: key pairPlainEncryptCipherPlainDecryptCiphersame secret keyPlainEncryptCipherPlainDecryptCipherpublic keyprivate keySymmetric is fast for bulk data; asymmetric solves key exchange and signatures
Figure 1. Symmetric encryption uses one shared key. Asymmetric encryption encrypts with the receiver's public key; only their private key can decrypt.
SymmetricAsymmetric (public key)
KeysOne secret key shared by both sidesA public key (shareable) and a private key (kept secret)
SpeedVery fast; used for bulk dataMuch slower; used for small data
Main challengeGetting the key safely to the other sideMaking sure a public key really belongs to its owner (certificates)
Current examplesAES (use this), ChaCha20RSA, elliptic-curve (ECC), Diffie-Hellman for key exchange, DSA/ECDSA for signatures
OutdatedDES, 3DES, RC4, IDEA, BlowfishRSA keys shorter than 2048 bits

In practice both are combined: protocols such as TLS and IPsec use asymmetric cryptography to agree a key securely, then symmetric AES to encrypt the data.

Cryptographic hash functions

A hash function turns any input into a fixed-length fingerprint (digest). A good cryptographic hash is:

  • one-way: you can't get the input back from the hash;
  • collision-resistant: it is infeasible to find two inputs with the same hash;
  • sensitive: changing one bit of input changes the output completely.
AlgorithmOutputStatus
MD5128 bitsBroken; only for non-security checksums
SHA-1160 bitsBroken for security; legacy only
SHA-256 / SHA-512 (SHA-2)256 / 512 bitsSecure; the everyday choice
SHA-3224–512 bitsSecure; different internal design

Try them yourself with the hash calculator.

HMAC and digital signatures

How HMAC proves integrity and authenticityMessageSecret keyHMAC-SHA256hash functionTag256-bit valueSend bothmessage + tagThe receiver repeats the calculation with the same key; a matching tag means unchanged and genuine
Figure 2. HMAC mixes a secret key into the hash, so only someone with the key can produce a valid tag.

A plain hash proves data wasn't changed, but anyone can recompute it. A Keyed-Hash Message Authentication Code (HMAC) mixes a shared secret key into the hash, so it proves both integrity and authenticity. IPsec, TLS and API signatures use HMAC.

A digital signature does the same with asymmetric keys: the sender signs a hash with their private key, and anyone can verify it with the sender's public key. This also provides non-repudiation, because only the private-key owner could have signed.

Practice

Encrypt CAT with a Caesar shift of 3.
FDW.
Why do protocols like TLS use both asymmetric and symmetric encryption?
Asymmetric safely agrees a shared key; symmetric (AES) then encrypts the data quickly.
What does HMAC add to a normal hash?
A secret key, so the tag also proves the message came from someone holding that key.

Key takeaways

  • Encryption turns plaintext into ciphertext using an algorithm and a key.
  • Classic ciphers use transposition or substitution; the one-time pad is unbreakable but impractical.
  • Symmetric (AES) is fast with one key; asymmetric (RSA, ECC) uses a key pair.
  • Use SHA-256 or better; MD5 and SHA-1 are broken for security.
  • HMAC proves integrity and authenticity; digital signatures add non-repudiation.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.