Skip to content
Threats Guide

Asymmetric Encryption (RSA)

DraftLast reviewed Oct 11, 2026Edit this page on GitHub

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

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.

References