Arkendia Classrooms
Lesson 22 of 28 · 17 min

Symmetric and Asymmetric Encryption: The Big Principles

Hashing gives you a fingerprint, but sometimes you need to hide the content itself and then recover it later: a private message, a stored database, a connection to your bank. That is encryption, and it comes in two great families that work in very different ways. Understanding their strengths and the clever way they are combined will unlock the next lesson on HTTPS and certificates, and will let you read any security design with more confidence.

In the previous lesson, you saw that hashing is one-way. Encryption is, by definition, reversible, but only for those who hold the right key. This lesson explains who holds which key.

The vocabulary

  • Plaintext: the readable data.
  • Ciphertext: the encrypted, unreadable result.
  • Algorithm (cipher): the public procedure that transforms the data.
  • Key: the secret value that parameterises the algorithm.

A principle named after Auguste Kerckhoffs, a 19th-century cryptographer, says that a system must stay secure even if everything about it, except the key, is public. Modern cryptography follows it: algorithms are published and studied by thousands of researchers, and only the key is secret. This is why "secret, homemade algorithms" are a red flag, while widely studied standard algorithms are trustworthy. Never design your own cipher.

Symmetric encryption: one shared key

In symmetric encryption, the same key encrypts and decrypts. Think of a padlock for which you and your friend have identical keys: either of you can lock or unlock the box.

  • Strengths: fast, efficient even for huge amounts of data, simple mathematically.
  • Weakness: the key distribution problem. How do you share the key with your friend securely, if you cannot yet communicate securely? And with n people who all need to talk privately in pairs, you need many keys.

The standard symmetric algorithm today is AES (Advanced Encryption Standard), which works with keys of 128, 192 or 256 bits. Older algorithms such as DES are obsolete because their keys are too short. AES encrypts data in blocks, so it needs a mode of operation to handle larger data. The mode matters a lot. Some modes, if used carelessly, leak patterns, and a common failure is picking a simple mode that encrypts identical blocks identically. Modern practice uses authenticated encryption modes (such as GCM), which provide confidentiality and also detect tampering. Another family of symmetric ciphers, stream ciphers, encrypt data as a continuous flow and are also in wide use.

Reusing a number that is meant to be used once (the nonce or initialisation vector) with the same key is a classic way to break an otherwise strong cipher. This is a reason why you should rely on well-designed libraries, which handle these details, and not assemble primitives yourself.

You can try symmetric encryption in your lab with OpenSSL, a widely available toolkit:

echo "lab secret" > secret.txt
openssl enc -aes-256-cbc -pbkdf2 -salt -in secret.txt -out secret.enc
openssl enc -d -aes-256-cbc -pbkdf2 -in secret.enc -out secret.dec
cat secret.dec

The tool asks for a passphrase, from which it derives the key (the option -pbkdf2 makes this derivation slow and robust, like password hashing). This command is fine to demonstrate the principle in your lab; for real data, prefer a dedicated tool that uses an authenticated mode.

Asymmetric encryption: a pair of keys

In asymmetric encryption, also called public-key cryptography, each person has a pair of keys that are mathematically linked: a public key, which can be shared with everyone, and a private key, which stays secret. What one key does, only the other can undo.

An analogy: a letterbox. Anyone can drop a letter through the slot (the public key is the address of the letterbox), but only the owner has the key to open it and read the letters (the private key).

It solves the distribution problem: to send a confidential message to Alice, you encrypt it with her public key, which she can publish openly, and only her private key can decrypt it. No prior secret exchange is needed.

  • Strengths: no need to share a secret in advance; enables digital signatures (see below).
  • Weakness: much slower than symmetric encryption, and limited in the size of data it handles directly. And a new problem arises: how do you know that a public key really belongs to Alice? (Lesson 3 answers.)

The most known algorithms are RSA (based on the difficulty of factoring large numbers) and those based on elliptic curves (ECC), which reach comparable security with much smaller keys. Key sizes are recommended by official bodies and evolve; follow current guidance. Some research aims at preparing for future quantum computers, which could weaken some of today's public-key algorithms, which is why standardisation bodies are working on "post-quantum" algorithms. You do not need the details now; just remember that cryptographic recommendations change over time, which is one more reason to rely on maintained libraries and to be able to replace algorithms ("crypto agility").

Digital signatures: proving who wrote it

Asymmetric cryptography also works in the other direction. If you encrypt (technically, sign) a hash of a document with your private key, anyone can verify it using your public key. Since only you hold the private key, the signature proves that the document comes from you (authenticity), has not been altered since (integrity), and you cannot easily deny having signed it (non-repudiation). Software projects sign their releases this way. This also completes the lesson on checksums: a signed checksum file means you do not have to trust the web page where it was published.

The best of both worlds: hybrid encryption

In practice, protocols combine the two. Asymmetric cryptography is used briefly at the beginning, to agree on or exchange a fresh symmetric key. Then, all the bulk of the data is encrypted quickly with that symmetric session key. This is exactly what happens when your browser opens an HTTPS connection, as we will see in lesson 3. A related technique, key exchange (such as Diffie-Hellman), allows two parties to agree on a shared secret over an open channel, and modern versions produce keys that are used only once, so that a later theft of a long-term key does not reveal past conversations. This property is called forward secrecy.

SymmetricAsymmetric
KeysOne shared secret keyA public and a private key
SpeedVery fastMuch slower
Main problemSharing the key safelyKnowing that a public key is genuine
Typical useEncrypting data and trafficKey exchange, signatures, identity
ExamplesAESRSA, elliptic curves

Encryption in transit and at rest

Two situations call for encryption. In transit means protecting data as it travels, as with HTTPS, SSH or a VPN. At rest means protecting stored data, such as an encrypted laptop disk or database. Remember the first course: full-disk encryption protects a stolen laptop. Neither protects data once it is decrypted in memory, or if the user's session is compromised, so encryption is one layer in a defence, not the whole defence.

Your turn: SSH keys, a real asymmetric pair

SSH, the secure remote shell, uses asymmetric keys for login. In your lab, from the Kali VM, generate a key pair with ssh-keygen -t ed25519 (accept the default location and set a passphrase). Look at the two files created in ~/.ssh: one ending in .pub and one without. Copy the public key to the Linux server of your lab with ssh-copy-id student@10.10.10.20, then log in again. In your notebook, explain which file you must never share, which file was copied to the server, and where on the server it was stored.

See a solution

You must never share the private key (the file without .pub, such as id_ed25519). The public key (id_ed25519.pub) is the one that is copied to the server, and it is appended to the file ~/.ssh/authorized_keys of the target user on the server. Next time you connect, the server challenges you to prove that you own the matching private key; your passphrase only unlocks the private key on your own machine and is never sent to the server. This is asymmetric cryptography at work, and it is usually considered much stronger than passwords for remote login, especially when combined with disabling password login on servers once keys work.

Private means private

A private key that leaks, for example by being committed to a public code repository or left on a shared drive, is a compromised identity. Protect it with a passphrase, with file permissions of 600 and, for high-value keys, with hardware devices.

Key takeaways

  • Symmetric encryption (for example AES) uses one shared key: fast, but the key must be shared safely.
  • Asymmetric encryption uses a public and a private key: it solves key distribution and enables signatures, but it is slower.
  • Real protocols are hybrid: asymmetric to agree on a key, symmetric to protect the data; forward secrecy protects past sessions.
  • Use standard algorithms and maintained libraries, never homemade ones; recommendations evolve.
  • Next lesson: certificates and TLS, where all of this makes HTTPS work.
Advertisement
Log in to save your progress. Log in