Skip to content

Asymmetric Encryption (RSA)

Asymmetric cryptography uses a key pair: anyone can encrypt or verify with the public key, but only the private key holder can decrypt or sign. It solves the problem of sharing a secret with someone you have never met.

DraftLast reviewed Oct 11, 20261 scriptEdit this page on GitHub

This page is a draft: its scripts were tested in a lab, but its references still need an independent review.

On this page

After this lesson you can

  • Explain what Asymmetric Encryption (RSA) is in your own words.
  • Describe how the attack or technique works.
  • Walk through a real-world example from start to finish.
  • Recognise it using the detection techniques in this lesson.
  • Apply the prevention methods described here.
  • Read and run the Python script in a lab you control.
  • Relate the topic to CWE-327 in the standards.

Last reviewed: 2026-10-11 | Status: Draft (new topic; scripts tested against local lab targets, references not yet independently re-verified)

Standards mapping

FrameworkReference
OWASP Top 10:2025Cryptographic Failures
MITRE ATT&CK (v19)not applicable
CWECWE-327 Use of a Broken or Risky Cryptographic Algorithm
CAPECnot applicable
Example CVECVE-2017-15361 (ROCA: weak RSA key generation in Infineon chips)

What it is

Asymmetric cryptography uses a key pair: anyone can encrypt or verify with the public key, but only the private key holder can decrypt or sign. It solves the problem of sharing a secret with someone you have never met.

How it works

RSA's security rests on the difficulty of factoring a large number. It is slow and can encrypt only a few hundred bytes, so real systems encrypt data with a random AES key and encrypt that key with RSA (hybrid encryption, shown in ../symmetric/aes_example.py). Padding is critical: OAEP for encryption and PSS for signatures.

Real-world example

The ROCA flaw (CVE-2017-15361), disclosed in 2017, showed that RSA keys produced by a widely used Infineon library had a structure that allowed the private key to be computed from the public key. The algorithm was fine; the key generation was not.

Detection

  • Inventory keys: find RSA keys below 2048 bits, keys generated by unknown libraries, and keys without an expiry
  • Watch for PKCS#1 v1.5 encryption in code reviews

Prevention

In order of strength. The first items fix the cause; the rest reduce risk.

  1. Use at least 3072-bit RSA for new keys (or elliptic-curve keys: Ed25519 for signatures, X25519 for key exchange)
  2. Use OAEP (SHA-256) for encryption and PSS for signatures; never textbook RSA or PKCS#1 v1.5 for encryption
  3. Protect private keys with a passphrase, file permissions or an HSM; generate keys with a vetted library
  4. Plan for post-quantum algorithms: NIST published its first post-quantum standards in 2024 (confirm current guidance before migrating)

Scripts in this topic

Common mistakes

  • Encrypting large files directly with RSA
  • Reusing one key pair for both encryption and signing
  • Generating keys with a home-made or outdated routine
  • Storing the private key unencrypted next to the application

Test it safely

Run rsa_example.py gen, then encrypt, decrypt, sign and verify files in a scratch folder.

Practical Python labs

Open a script to read its source and copy the run commands. Run security tools only on systems you own or have written permission to test.

Check what you have covered

These questions are generated from this lesson's category, standards mapping and scripts. They test where things live in the guide, not how well you understand the concepts. Nothing is saved or tracked.

1.Which category is "Asymmetric Encryption (RSA)" part of?
2.Which CWE identifier is listed in the standards mapping for "Asymmetric Encryption (RSA)"?
3.Which of these scripts belongs to the "Asymmetric Encryption (RSA)" lesson?

References