0Pricing
Cryptology Academy · Lesson

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

  1. Python cryptography Library Overview
  2. AES-GCM Encrypt & Decrypt in Python
  3. RSA & ECDSA Key Pairs in Python
  4. Common Python Crypto Pitfalls & Secure Patterns
← Back to Cryptology Academy