Applied Cryptography and PKI
Applied cryptography uses mathematical techniques to protect information, verify identities, and detect unauthorized changes. The main concepts in this topic are symmetric encryption, asymmetric encryption, hashing, digital signatures, Public Key Infrastructure, and SSL/TLS.
Together, these technologies support the three major security goals:
Confidentiality: Only authorized parties can read the data.
Integrity: Data cannot be changed without detection.
Authentication: A user, system, or organization can prove its identity.
TLS combines these ideas to protect communications such as HTTPS. NIST describes TLS as a mechanism for protecting data during electronic transmission and recommends careful configuration of TLS implementations and cryptographic algorithms.
1. Symmetric Encryption
Concept
Symmetric encryption uses the same secret key to encrypt and decrypt data.
Plaintext + Secret Key → Ciphertext
Ciphertext + Same Secret Key → Plaintext
Example:
Alice and Bob share the key: K
Alice encrypts a message using K.
Bob decrypts the message using K.
The key must remain secret. Anyone who obtains it may be able to decrypt the protected data.
Common symmetric algorithms
AES.
ChaCha20.
3DES, mainly legacy.
DES, obsolete and insecure.
AES is commonly used because it provides strong security and efficient performance. ChaCha20-Poly1305 is also widely used, especially when hardware acceleration for AES is unavailable.
Modes of operation
Block ciphers such as AES require a mode of operation.
Common examples include:
CBC.
CTR.
GCM.
XTS.
Authenticated encryption modes such as AES-GCM provide confidentiality and integrity together. They help ensure that encrypted data has not been modified.
Advantages
Fast.
Efficient for large amounts of data.
Suitable for disk, database, file, and network encryption.
Requires relatively low processing power.
Disadvantage
The main challenge is key distribution. Both parties need the same secret key, but securely sharing that key can be difficult.
Example uses
Full-disk encryption.
Encrypted database fields.
File encryption.
VPN data channels.
Wi-Fi encryption.
TLS session data.
2. Asymmetric Encryption
Concept
Asymmetric encryption uses a pair of mathematically related keys:
Public key: Can be shared openly.
Private key: Must be kept secret.
Data encrypted with one key is processed using the corresponding other key.
For confidentiality:
Sender encrypts with recipient’s public key.
Recipient decrypts with their private key.
For digital signatures:
Signer creates a signature using their private key.
Others verify it using the signer’s public key.
Common asymmetric algorithms
RSA.
Elliptic Curve Cryptography, or ECC.
Elliptic Curve Diffie-Hellman, or ECDH.
Elliptic Curve Digital Signature Algorithm, or ECDSA.
Diffie-Hellman, or DH.
Modern systems commonly use elliptic-curve algorithms because they can provide strong security with smaller keys than traditional RSA systems.
Advantages
Solves the key-distribution problem more effectively than symmetric encryption.
Supports digital signatures.
Enables identity verification.
Supports secure key exchange.
Disadvantages
Slower than symmetric encryption.
Requires certificate and key-management processes.
Private-key compromise can be very serious.
Incorrect validation can allow man-in-the-middle attacks.
Encryption versus key exchange
Asymmetric cryptography is often used to establish or exchange a symmetric session key. After that, symmetric encryption protects the actual data because it is faster.
This combination is called hybrid encryption.
3. Symmetric versus Asymmetric Encryption
Feature | Symmetric encryption | Asymmetric encryption |
|---|---|---|
Keys used | One shared secret key | Public and private key pair |
Speed | Fast | Slower |
Best use | Large data volumes | Authentication and key exchange |
Key distribution | Difficult if parties have not met | Public key can be shared |
Supports digital signatures | Not by itself | Yes |
Examples | AES, ChaCha20 | RSA, ECC, ECDH |
Common TLS role | Encrypts application data | Authenticates and establishes session keys |
Practical example
When you visit an HTTPS website:
The server presents a certificate and public key.
The browser validates the certificate.
The client and server establish shared session-key material.
Symmetric encryption protects the rest of the session.
The asymmetric operations establish trust and keys, while symmetric encryption handles the high-volume data transfer.
4. Hashing
Concept
A cryptographic hash function converts input data of any size into a fixed-length output called a hash, digest, or fingerprint.
Input data → Hash function → Fixed-length digest
Even a small change to the input should produce a substantially different hash.
Example:
Message A → Hash A
Message B → Completely different Hash B
Properties of a secure hash
A cryptographic hash should provide:
Determinism: The same input produces the same hash.
Preimage resistance: It should be difficult to recover the original input from the hash.
Second-preimage resistance: It should be difficult to find another input with the same hash as a given input.
Collision resistance: It should be difficult to find any two different inputs with the same hash.
Avalanche effect: A small input change causes a large output change.
Common hash algorithms
SHA-256.
SHA-384.
SHA-512.
SHA-3.
Algorithms such as MD5 and SHA-1 should not be used for new security-sensitive designs because of collision weaknesses.
Hashing is not encryption
Hashing is generally one-way, while encryption is designed to be reversible using a key.
Hashing | Encryption |
|---|---|
Usually one-way | Reversible with a key |
Produces a digest | Produces ciphertext |
Used for integrity and password verification | Used for confidentiality |
Does not use decryption | Requires decryption to recover plaintext |
Password storage
Passwords should not be stored as plain text. They should be processed using a password-hashing function with a unique salt.
Common password-hashing algorithms include:
Argon2.
bcrypt.
scrypt.
PBKDF2.
A salt is a random value stored with the password hash. It ensures that identical passwords do not automatically produce identical stored hashes and makes precomputed attacks more difficult.
A fast general-purpose hash such as SHA-256 alone is not ideal for password storage because attackers can calculate large numbers of hashes quickly.
File integrity example
A software publisher may publish a SHA-256 hash of an installation file. After downloading it, a user calculates the file’s hash and compares the result.
Published hash = A1B2C3...
Downloaded-file hash = A1B2C3...
If the values match, the file probably has not changed. However, a hash alone does not prove who published the file. For authenticity, a digital signature is stronger.
5. Message Authentication Codes
A Message Authentication Code, or MAC, verifies the integrity and authenticity of a message using a shared secret key.
A common type is HMAC:
HMAC = Hash function + Secret key
For example, HMAC-SHA-256 uses SHA-256 together with a secret key.
A MAC can help answer:
Was the message changed?
Was it created by someone who knows the shared secret?
Unlike a digital signature, a MAC does not allow independent third-party verification because both parties share the same secret key.
6. Digital Signatures
Concept
A digital signature is a cryptographic value that helps prove:
Who signed the data.
That the data was not modified.
That the signature was created using the corresponding private key.
NIST identifies digital signatures as supporting identity authentication, integrity authentication, source authentication, and non-repudiation.nvlpubs.nist
Digital signature process
Suppose Angel signs a document:
A hash of the document is calculated.
Angel uses a private key to sign the hash.
The document and signature are sent to the recipient.
The recipient calculates a new hash of the document.
The recipient uses Angel’s public key to verify the signature.
If the values match, the document is considered intact and associated with Angel’s key.
Simplified process:
Document → Hash → Sign with private key → Digital signature
Verification:
Document → Hash
Signature + Public key → Recovered or verified value
Compare both values
What a digital signature provides
Integrity: Detects changes to the signed data.
Authentication: Associates the signature with a private key.
Non-repudiation support: Provides evidence that a key holder signed the data, although legal non-repudiation also depends on policies and identity assurance.
What a digital signature does not provide
A digital signature does not automatically hide the contents of a document. It provides authenticity and integrity, not confidentiality.
If confidentiality is required, the document must also be encrypted.
Common uses
Signed software.
Document approval.
Secure email.
Code signing.
Digital certificates.
Online contracts.
Package repositories.
Firmware updates.
TLS certificates.
7. Public Key Infrastructure
Concept
Public Key Infrastructure, or PKI, is the system of policies, people, technologies, certificates, and procedures used to create and manage public-key identities.
NIST describes PKI as security infrastructure that creates and manages public-key certificates for asymmetric cryptography.nvlpubs.nist
PKI helps answer this question:
How can users trust that a public key actually belongs to the person, device, or website claiming it?
Main PKI components
Certificate Authority
A Certificate Authority, or CA, issues and signs digital certificates. The CA is trusted to verify identities according to its policies.
Examples of CA roles include:
Root CA.
Intermediate CA.
Public CA.
Internal enterprise CA.
Root CA
The root CA is the top-level trust authority. Its certificate is usually self-signed and is placed in trusted certificate stores.
Because compromise of a root CA is extremely serious, root CAs are usually carefully protected and may remain offline.
Intermediate CA
An intermediate CA receives authority from a root CA and issues certificates to servers, users, or devices.
This creates a certificate chain:
Root CA
↓ signs
Intermediate CA
↓ signs
Website or user certificate
Registration Authority
A Registration Authority, or RA, verifies the identity of certificate applicants before a CA issues certificates.
Digital certificate
A digital certificate binds an identity to a public key. It commonly contains:
Subject name.
Public key.
Issuer.
Validity period.
Serial number.
Key usage.
Subject Alternative Name.
Digital signature from the issuing CA.
TLS server certificates commonly use the X.509 format. NIST TLS guidance discusses X.509 certificates, certificate chains, key strength, signature algorithms, and certificate configuration.nvlpubs.nist
Certificate repository
A repository stores certificates, revocation information, and related PKI data.
Certificate revocation mechanisms
Certificates may need to be invalidated before their expiration date because:
A private key was compromised.
The certificate was issued incorrectly.
The organization no longer controls the domain.
The device or user is no longer authorized.
Common mechanisms include:
Certificate Revocation Lists, or CRLs.
Online Certificate Status Protocol, or OCSP.
Short-lived certificates.
Certificate validation
When a browser connects to a website, it may check:
Whether the certificate is signed by a trusted CA.
Whether the certificate is within its validity period.
Whether the domain matches the certificate.
Whether the certificate chain is valid.
Whether the certificate has been revoked.
Whether the certificate uses acceptable algorithms.
If validation fails, the browser may display a certificate warning.
8. SSL and TLS
Concept
SSL stands for Secure Sockets Layer. TLS stands for Transport Layer Security. TLS replaced SSL because older SSL versions are obsolete and insecure.
TLS protects communications by providing:
Confidentiality.
Integrity.
Server authentication.
Optional client authentication.
NIST explains that TLS protects data transmitted across networks and provides guidance for selecting and configuring TLS implementations.csrc.nist
Where TLS is used
HTTPS websites.
Secure email.
APIs.
VPNs.
Database connections.
Messaging systems.
Cloud services.
IoT device communications.
For a website:
HTTP + TLS = HTTPS
Simplified TLS connection
Client → ClientHello
Server → ServerHello + Certificate
Client → Validates certificate
Both sides → Establish shared secret/session keys
Both sides → Exchange encrypted application data
The actual TLS protocol is more detailed, but the main idea is that public-key cryptography helps establish trust and session keys, while symmetric encryption protects the continuing connection.
TLS handshake purposes
The handshake may:
Negotiate protocol versions.
Select cryptographic algorithms.
Authenticate the server.
Establish shared key material.
Confirm that both parties possess the required secrets.
Create keys for encrypted communication.
TLS 1.2 and TLS 1.3
TLS 1.2 remains widely deployed when securely configured. TLS 1.3 simplifies the handshake and removes several older cryptographic options.
Organizations should avoid obsolete protocols and weak cipher suites. NIST’s TLS guidance addresses protocol versions, cipher suites, certificates, digital signatures, and cryptographic configuration.csrc.nist+1
Cipher suites
A cipher suite identifies the cryptographic mechanisms used by a TLS connection. It may specify:
Key exchange.
Authentication or digital signature.
Symmetric encryption.
Integrity protection.
A simplified example is:
TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
This name indicates several cryptographic components, although TLS 1.3 uses a different naming structure.
Perfect forward secrecy
Perfect Forward Secrecy, or PFS, ensures that compromise of a server’s long-term private key does not automatically reveal previously recorded sessions.
Ephemeral Diffie-Hellman methods, such as ECDHE, are commonly used to provide forward secrecy.
Server authentication
TLS protects against man-in-the-middle attacks by allowing the client to verify the server’s certificate. If certificate validation is skipped or incorrectly implemented, an attacker may impersonate the server.
Client authentication
In ordinary HTTPS, the server authenticates to the client. In some systems, both sides authenticate using certificates. This is called mutual TLS, or mTLS.
mTLS is useful for:
Service-to-service communication.
Internal APIs.
IoT devices.
Enterprise applications.
High-security administrative systems.
9. Example: HTTPS in Practice
Suppose a user visits:
https://example.com
The process is broadly:
The browser resolves the domain name.
The browser connects to the server.
The server sends its TLS certificate.
The browser checks the certificate and trust chain.
The browser and server negotiate compatible cryptographic parameters.
They establish shared session keys.
HTTPS data is encrypted and integrity-protected.
The browser displays the page.
The certificate helps authenticate the server. Asymmetric cryptography supports the handshake. Symmetric encryption protects the ongoing session. Integrity mechanisms detect tampering.
10. Key Management
Cryptography is only as secure as its key management.
Key-management activities
Key generation.
Key storage.
Key distribution.
Key rotation.
Key backup.
Key recovery.
Key revocation.
Key destruction.
Access auditing.
Private-key protection
Private keys should be:
Kept secret.
Protected with access controls.
Stored in secure hardware or protected key stores where appropriate.
Backed up carefully.
Rotated according to policy.
Revoked when compromised.
Removed securely when no longer needed.
Hardware Security Module
A Hardware Security Module, or HSM, is a specialized device designed to protect cryptographic keys and perform cryptographic operations.
HSMs may be used by:
Certificate Authorities.
Banks.
Cloud providers.
Payment systems.
Government agencies.
Large enterprises.
11. Common Cryptography Mistakes
Using outdated SSL, TLS, DES, or weak cipher suites.
Treating Base64 as encryption.
Storing passwords as plain text.
Using unsalted password hashes.
Reusing encryption keys for unrelated purposes.
Hardcoding private keys in source code.
Failing to validate TLS certificates.
Ignoring certificate expiration.
Using SHA-1 or MD5 for new security-sensitive applications.
Using predictable random numbers.
Encrypting data without protecting the encryption key.
Assuming a digital signature provides confidentiality.
Disabling certificate validation to solve a development error.
Failing to revoke compromised certificates.
Using a single long-lived key indefinitely.
12. Comparison Table
Mechanism | Main purpose | Key requirement | Reversible? | Example |
|---|---|---|---|---|
Symmetric encryption | Confidentiality | Shared secret key | Yes | AES |
Asymmetric encryption | Confidentiality and key exchange | Public/private key pair | Yes, with corresponding key | RSA, ECC |
Hashing | Integrity and fingerprinting | No encryption key required | No | SHA-256 |
HMAC | Integrity and shared-key authentication | Shared secret key | No | HMAC-SHA-256 |
Digital signature | Integrity and origin authentication | Private signing key and public verification key | Verification-based | RSA-PSS, ECDSA |
PKI | Trust and certificate management | CAs and certificates | Not directly | X.509 |
TLS | Secure network communication | Certificates and session keys | Uses both asymmetric and symmetric methods | HTTPS |