Online admissions open for the SEO, web development and networking & cybersecurity courses. Enquire for the next batch.

Cryptography Basics: Symmetric, Asymmetric, TLS and PKI

5 min read Updated By the SkillNewton team

What is cryptography?

Cryptography is the use of mathematical algorithms and secret keys to protect information. It keeps data confidential so only intended readers can see it, proves the data has not been altered, and proves who sent it. Modern systems combine symmetric ciphers such as AES, asymmetric algorithms such as RSA and elliptic curves, hash functions and certificates.

The goals: confidentiality, integrity and authenticity

  • Confidentiality: only someone with the right key can read the data. Achieved with encryption.
  • Integrity: any change to the data is detected. Achieved with hashes, MACs and authenticated encryption.
  • Authenticity: you can confirm who created the data or who you are talking to. Achieved with MACs, digital signatures and certificates.
  • Non-repudiation: a signer cannot later deny signing, because only they hold the private key.

These goals map onto the confidentiality, integrity and availability triad described in our cybersecurity basics guide. Cryptography handles the first two directly; availability needs other controls.

Key terms

  • Plaintext and ciphertext: the readable data and its encrypted form.
  • Key: the secret value that controls the algorithm. Security rests on the key, not on hiding the algorithm (Kerckhoffs's principle).
  • Nonce or IV: a value that must not repeat for the same key, so identical messages encrypt differently.

Symmetric encryption: AES

Symmetric encryption uses the same key to encrypt and decrypt. It is fast, so it protects almost all bulk data: disk encryption, VPN tunnels, database fields and the data part of every HTTPS connection.

AES (Advanced Encryption Standard, NIST FIPS 197) is a block cipher with a 128-bit block and keys of 128, 192 or 256 bits. A block cipher needs a mode to encrypt more than one block. Use an authenticated mode such as AES-GCM, which encrypts and detects tampering in one step. ChaCha20-Poly1305 is the common alternative on devices without AES hardware support. Avoid ECB mode, which leaks patterns in the data.

The hard part of symmetric encryption is not the cipher but key distribution: both sides need the same secret key without an eavesdropper learning it.

Asymmetric encryption: RSA and elliptic curves

Asymmetric (public key) cryptography uses a key pair. The public key can be shared with anyone; the private key never leaves its owner. Data encrypted with the public key can only be decrypted with the private key, and a signature made with the private key can be verified by anyone holding the public key.

AlgorithmBased onTypical useNotes
RSADifficulty of factoring large numbersSignatures, older key transportUse 2048-bit keys or larger
ECDSA (P-256)Elliptic curve discrete logarithmTLS certificates, code signingMuch smaller keys than RSA
Ed25519Edwards curveSSH keys, modern signaturesFast and hard to misuse
X25519 / ECDHEElliptic curve Diffie-HellmanKey exchange in TLS and VPNsProvides forward secrecy

Asymmetric operations are far slower than AES, so real systems use them only to agree on or protect a symmetric key and to sign data. This combination is called hybrid encryption. To prepare for future quantum computers, NIST published the ML-KEM and ML-DSA post-quantum standards in 2024, and major browsers already negotiate hybrid key exchanges that combine X25519 with ML-KEM.

Key exchange and the TLS 1.3 handshake

Diffie-Hellman key exchange lets two parties agree on a shared secret over a public network: each sends a public value, and each combines the other's value with its own private value to reach the same secret. An eavesdropper who sees both public values cannot compute it. Using fresh (ephemeral) values per session gives forward secrecy, so a stolen server key cannot decrypt recorded past sessions.

TLS 1.3 (RFC 8446) secures HTTPS and many other protocols. A simplified full handshake looks like this:

  1. ClientHello: the client lists supported cipher suites and sends its key share for the key exchange.
  2. ServerHello: the server picks a cipher suite and sends its own key share. Both sides now derive the handshake keys, and everything after this point is encrypted.
  3. Certificate and CertificateVerify: the server sends its certificate chain and signs the handshake with its private key, proving it owns the certificate.
  4. Finished: both sides confirm the handshake was not tampered with, then switch to application keys for HTTP data.

TLS 1.3 completes this in one round trip, removed static RSA key transport and allows only AEAD ciphers such as AES-GCM and ChaCha20-Poly1305. You can inspect a live handshake with OpenSSL:

openssl s_client -connect example.com:443 -servername example.com -tls1_3 < /dev/null
# Look for: Protocol: TLSv1.3, the Cipher line, and "Verify return code: 0 (ok)"

TLS runs over TCP port 443 for HTTPS, as listed in network ports and protocols.

Digital signatures, certificates and PKI

A digital signature is made by hashing a message and processing the hash with the signer's private key. The verifier recomputes the hash and checks it with the public key. If even one bit of the message changes, verification fails.

openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:P-256 -out key.pem
openssl pkey -in key.pem -pubout -out pub.pem
openssl dgst -sha256 -sign key.pem -out msg.sig msg.txt
openssl dgst -sha256 -verify pub.pem -signature msg.sig msg.txt   # prints: Verified OK

A signature proves which key signed, but not whose key it is. Public Key Infrastructure (PKI) solves that. A certificate authority (CA) issues an X.509 certificate binding a public key to a domain or organisation, and signs it. Browsers trust a set of root CAs; roots sign intermediate certificates, which sign the server's leaf certificate. The client checks the chain, the domain name, the validity dates and revocation status.

openssl s_client -connect example.com:443 -servername example.com -showcerts < /dev/null \
  | openssl x509 -noout -subject -issuer -dates -ext subjectAltName

Practical exercise: inspect and verify real cryptography

  1. Run the s_client command against two HTTPS sites you use and record the TLS version, cipher suite and key exchange group for each.
  2. Print each site's certificate subject, issuer, validity dates and subject alternative names.
  3. Generate a P-256 key pair, sign a text file and verify the signature.
  4. Change one character in the file and verify again; record the error.
  5. Explain in three sentences which steps gave confidentiality, integrity and authenticity.

You are done when your notes show both certificate chains, a successful and a failed verification, and your three-sentence explanation. Cryptography in VPNs and secure protocols is covered further in the Advanced Networking course; see also encryption and hashing compared.

Common mistakes

  • Inventing a custom encryption scheme instead of using a vetted library and standard algorithms.
  • Reusing a nonce with the same key in AES-GCM, which can expose plaintext and allow forgery.
  • Using ECB mode or unauthenticated CBC for new designs.
  • Storing private keys in source code repositories or sharing them by email.
  • Disabling certificate verification in code to silence an error, which removes protection against interception.

Frequently asked questions

Is AES-128 still secure?

Yes. AES-128 has no practical attack against it when used correctly. AES-256 is used where policy requires it or for a larger margin against future quantum attacks.

What is the difference between SSL and TLS?

TLS replaced SSL. All SSL versions and TLS 1.0 and 1.1 are deprecated; servers should offer TLS 1.2 and 1.3 only. People still say "SSL certificate" out of habit.

Does HTTPS mean a website is safe?

No. HTTPS proves the connection is encrypted and the certificate matches the domain. A phishing site can have a valid certificate too, so check the domain itself, as explained in recognising phishing.

Want to Learn This Properly?

The Advanced Networking & Cybersecurity Mastery (Online) turns guides like this into practised skills, with projects on real websites.

WhatsApp Call Us Now

Free counselling

Send an Enquiry

Tell us which course you are interested in. We reply by email or phone with the next batch and how to enrol.

Protected by reCAPTCHA. Google Privacy and Terms apply.

We reply by email or phone within working hours. No spam.