0Pricing
Cloud & IT Cert Prep · Lesson

Asymmetric Encryption and Key Pairs

Understand RSA and elliptic curve cryptography, how public/private key pairs enable secure communication without sharing secrets.

Asymmetric Encryption and Key Pairs is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

How Asymmetric Encryption Works

Asymmetric encryption (also called public-key cryptography) uses mathematically linked key pairs: a public key that can be freely distributed, and a private key that must be kept secret. Data encrypted with the public key can only be decrypted with the corresponding private key — and vice versa. This elegant design solves the key distribution problem of symmetric encryption: you can share your public key openly without compromising security, because only your private key can decrypt messages sent to you.

RSA: The Most Widely Used Algorithm

RSA (Rivest-Shamir-Adleman) is the most widely deployed asymmetric encryption algorithm, invented in 1977. Its security relies on the mathematical difficulty of factoring the product of two large prime numbers. RSA supports key lengths of 1024, 2048, and 4096 bits — 2048-bit RSA is the current minimum recommendation, with 4096-bit for long-term security. RSA is used for key exchange in TLS (though increasingly replaced by ECDHE), digital signatures in certificates, and S/MIME email encryption.

# Generate an RSA 2048-bit key pair
openssl genrsa -out private.pem 2048

# Extract the public key
openssl rsa -in private.pem -pubout -out public.pem

# Encrypt with public key (only private key can decrypt)
openssl rsautl -encrypt -inkey public.pem -pubin -in message.txt -out encrypted.bin

# Decrypt with private key
openssl rsautl -decrypt -inkey private.pem -in encrypted.bin

Elliptic Curve Cryptography (ECC)

Elliptic Curve Cryptography (ECC) achieves equivalent security to RSA using much shorter key lengths. A 256-bit ECC key provides security comparable to a 3072-bit RSA key. This efficiency makes ECC ideal for resource-constrained environments like mobile devices, IoT hardware, and TLS connections where performance matters. ECC relies on the mathematical difficulty of the elliptic curve discrete logarithm problem. Common ECC algorithms include ECDSA (Elliptic Curve Digital Signature Algorithm) and ECDH (key exchange). TLS 1.3 requires ECC-based key exchange.

# Generate an ECC key pair using the P-256 (secp256r1) curve
openssl ecparam -name prime256v1 -genkey -noout -out ec_private.pem

# Extract public key
openssl ec -in ec_private.pem -pubout -out ec_public.pem

# ECC 256-bit ~ RSA 3072-bit in security strength
# Much faster operations, smaller keys = faster TLS handshakes

Public Key Use: Encryption Direction

Understanding the direction of key usage is critical for the Security+ exam. There are two distinct use cases that reverse the key roles. For encryption for confidentiality: the sender encrypts with the recipient's public key, and only the recipient can decrypt with their private key. For digital signatures for authentication: the signer encrypts the hash with their own private key, and anyone can verify using the signer's public key. Getting these directions backwards is a common exam mistake — remember: public key encrypts, private key decrypts; private key signs, public key verifies.

Digital Signatures with Asymmetric Keys

Digital signatures use asymmetric cryptography to provide authentication, integrity, and non-repudiation. The process is: (1) the sender computes a hash of the message, (2) encrypts the hash with their private key to create the signature, (3) sends the message and signature together. The receiver: (4) decrypts the signature using the sender's public key to recover the hash, (5) independently hashes the received message, and (6) compares the two hashes — a match proves the message is authentic and unaltered.

# Sign a document with ECDSA private key
openssl dgst -sha256 -sign ec_private.pem -out document.sig document.txt

# Verify the signature with the public key
openssl dgst -sha256 -verify ec_public.pem -signature document.sig document.txt
# Output: Verified OK (or Verification Failure)

Why Asymmetric Encryption Is Slow

Asymmetric encryption is computationally expensive compared to symmetric encryption — typically 100 to 1000 times slower. This is because asymmetric algorithms perform complex mathematical operations (modular exponentiation for RSA, point multiplication on curves for ECC) on large numbers. For this reason, asymmetric encryption is never used to encrypt bulk data directly. Instead, it is used to securely exchange a small symmetric session key, and the symmetric key then encrypts the actual data. This hybrid approach combines the security advantages of both approaches.

Key Pair Generation and Storage

Proper key pair management is essential. Private keys should be generated in a Hardware Security Module (HSM) or kept in an encrypted key store, never stored as unprotected plaintext files. Key pairs have a limited validity period, after which they must be regenerated. For certificate-based key pairs, the private key must never leave the device or HSM it was generated on. Compromise of a private key means an attacker can impersonate the key owner and decrypt all messages encrypted with the corresponding public key.

Public Key Infrastructure Context

Asymmetric key pairs only provide security if you can trust that a public key actually belongs to whom you think it does. Without a trust mechanism, an attacker could substitute their public key for your intended recipient's key — a classic man-in-the-middle attack. Public Key Infrastructure (PKI) solves this by having a trusted Certificate Authority (CA) digitally sign a certificate that binds a public key to a verified identity. When you visit an HTTPS website, your browser verifies the server's certificate against a CA it trusts, confirming the public key is legitimate.

Comparing RSA and ECC

When choosing between RSA and ECC, consider three factors. Key size efficiency: ECC 256-bit = RSA 3072-bit in security. Performance: ECC is significantly faster, especially on mobile and IoT devices. Adoption: RSA has broader legacy support; ECC is required in TLS 1.3 and increasingly mandated by modern security standards. Both algorithms are still considered secure when properly implemented with current recommended key sizes. The Security+ exam expects you to know these trade-offs and when each is appropriate.

Quantum Computing Threat to Asymmetric

Asymmetric encryption faces a long-term threat from quantum computers. Shor's algorithm, when run on a sufficiently powerful quantum computer, can solve the factoring problem (breaking RSA) and the discrete logarithm problem (breaking ECC) in polynomial time — making currently secure key sizes breakable. NIST has already selected post-quantum cryptographic algorithms including CRYSTALS-Kyber (key encapsulation) and CRYSTALS-Dilithium (digital signatures) to replace RSA and ECC. Organizations handling data with long-term sensitivity should begin planning for post-quantum migration now.

Asymmetric Encryption Use Cases

Asymmetric encryption underpins many of the security mechanisms you use every day. HTTPS: the TLS handshake uses RSA or ECC to exchange session keys. SSH: public key authentication replaces passwords with key pairs. Code signing: software vendors sign their code with private keys; your OS verifies with the public key. S/MIME email: encrypt email with recipient's public key and sign with your private key. Bitcoin/blockchain: transactions are signed with ECDSA private keys. Understanding where these mechanisms appear in practice helps contextualize exam questions.

# SSH public key authentication
# Generate ED25519 key pair (modern, faster than RSA)
ssh-keygen -t ed25519 -C 'alice@company.com'
# ED25519 is based on elliptic curves - fast and secure
# Public key goes to server: ~/.ssh/authorized_keys
# Private key stays local: ~/.ssh/id_ed25519 (protect with passphrase)

Quick Check

Test your understanding of CompTIA Security+ (SY0-701) concepts from this lesson.

Lesson Recap

In this lesson you learned: asymmetric encryption uses mathematically linked key pairs; RSA and ECC are the dominant algorithms (ECC is faster with shorter keys); public keys encrypt for confidentiality and private keys sign for authentication; and asymmetric encryption is slow but solves key distribution. Next up we explore Hashing and Data Integrity.

Frequently asked questions

Is the “Asymmetric Encryption and Key Pairs” lesson free?

Yes — the full text of “Asymmetric Encryption and Key Pairs” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.

What will I learn in “Asymmetric Encryption and Key Pairs”?

Understand RSA and elliptic curve cryptography, how public/private key pairs enable secure communication without sharing secrets. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cloud & IT Cert Prep?

No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Asymmetric Encryption and Key Pairs” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cloud & IT Cert Prep lesson?

Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Symmetric Encryption Algorithms
  2. Asymmetric Encryption and Key Pairs
  3. Hashing and Data Integrity
  4. Key Exchange and Hybrid Encryption
← Back to Cloud & IT Cert Prep