Last reviewed: 2026-10-11 | Status: Draft (new topic; scripts tested against local lab targets, references not yet independently re-verified)
Standards mapping
| Framework | Reference |
|---|---|
| OWASP Top 10:2025 | Cryptographic Failures |
| MITRE ATT&CK (v19) | not applicable |
| CWE | CWE-327 Use of a Broken or Risky Cryptographic Algorithm |
| CAPEC | not applicable |
| Example CVE | CVE-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.
- Use at least 3072-bit RSA for new keys (or elliptic-curve keys: Ed25519 for signatures, X25519 for key exchange)
- Use OAEP (SHA-256) for encryption and PSS for signatures; never textbook RSA or PKCS#1 v1.5 for encryption
- Protect private keys with a passphrase, file permissions or an HSM; generate keys with a vetted library
- Plan for post-quantum algorithms: NIST published its first post-quantum standards in 2024 (confirm current guidance before migrating)
Scripts in this topic
- rsa_example.py: key generation, OAEP encryption, PSS signatures
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
- NIST SP 800-57 Part 1 key management recommendations
- RFC 8017 PKCS #1: RSA Cryptography Specifications