RSA & ECDSA Key Pairs in Python
Generate, serialize, and use RSA and EC keys for signing and encryption.
Key Pair Operations Overview
Python's cryptography library supports RSA and ECDSA for generating keys, signing, verifying, serialising, and loading. These are the building blocks for TLS certificates, code signing, and JWTs.
Generating an RSA Key Pair
Minimum recommended: 2048-bit for compatibility, 4096-bit for long-lived keys:
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.backends import default_backend
private_key = rsa.generate_private_key(
public_exponent=65537,
key_size=2048,
backend=default_backend()
)
public_key = private_key.public_key()
print("RSA key generated, size:", private_key.key_size, "bits")All lessons in this course
- Python cryptography Library Overview
- AES-GCM Encrypt & Decrypt in Python
- RSA & ECDSA Key Pairs in Python
- Common Python Crypto Pitfalls & Secure Patterns