pydoc > rsa

📛 NAME

rsa — RSA module

🚀 Quick Reference

Use CaseCommandDescription
Generate key pairpub_key, priv_key = rsa.newkeys(2048)Create public/private keys with 2048-bit modulus
Encrypt a messagecrypto = rsa.encrypt(message, pub_key)Encrypt bytes using PKCS#1 v1.5
Decrypt a messagecleartext = rsa.decrypt(crypto, priv_key)Decrypt using the private key
Sign a messagesignature = rsa.sign(message, priv_key, 'SHA-256')Create a detached signature
Verify a signaturehash_name = rsa.verify(message, signature, pub_key)Verify and return hash method used
Load PEM keykey = rsa.PublicKey.load_pkcs1(pem_bytes)Load PKCS#1 PEM/DER key
Save key to PEMpem = pub_key.save_pkcs1()Export key as PEM bytes

📝 DESCRIPTION

Module for calculating large primes, and RSA encryption, decryption, signing and verification. Includes generating public and private keys.

⚠️ WARNING: this implementation does not use compression of the cleartext input to prevent repetitions, or other common security improvements. Use with care.

📦 PACKAGE CONTENTS

🏛️ CLASSES

🔑 PrivateKey

PrivateKey(n: int, e: int, d: int, p: int, q: int) -> None

Represents a private RSA key (the decryption key). Contains the n, e, d, p, q and other values. Supports attribute access and dictionary-like access.

>>> PrivateKey(3247, 65537, 833, 191, 17)
PrivateKey(3247, 65537, 833, 191, 17)

Calculated attributes:

>>> pk = PrivateKey(3727264081, 65537, 3349121513, 65063, 57287)
>>> pk.exp1
55063
>>> pk.exp2
10095
>>> pk.coef
50797

⚙️ Methods

📌 Attributes

Inherits from AbstractKey: blind(), unblind(), save_pkcs1(), load_pkcs1() (class method), and attributes blindfac, blindfac_inverse, mutex.

🔐 PublicKey

PublicKey(n: int, e: int) -> None

Represents a public RSA key (the encryption key). Contains the n and e values. Supports attribute access and dictionary-like access.

>>> PublicKey(5, 3)
PublicKey(5, 3)
>>> key = PublicKey(5, 3)
>>> key.n
5
>>> key['n']
5
>>> key.e
3
>>> key['e']
3

📌 Attributes

⚙️ Class Methods

Inherits from AbstractKey: blind(), unblind(), save_pkcs1(), load_pkcs1() (class method), and attributes blindfac, blindfac_inverse, mutex.

⚠️ DecryptionError (extends CryptoError)

Raised when decryption fails.

⚠️ VerificationError (extends CryptoError)

Raised when verification fails.

🔧 FUNCTIONS

📊 DATA

__all__ = ['newkeys', 'encrypt', 'decrypt', 'sign', 'verify', 'PublicKey', 'PrivateKey', 'DecryptionError', 'VerificationError']

🔢 VERSION

4.8

📅 DATE

2021-11-24

👤 AUTHOR

Sybren Stuvel, Barry Mead and Yesudeep Mangalapilly

📁 FILE

/usr/lib/python3/dist-packages/rsa/__init__.py

rsa
📛 NAME 🚀 Quick Reference 📝 DESCRIPTION 📦 PACKAGE CONTENTS 🏛️ CLASSES
🔑 PrivateKey 🔐 PublicKey ⚠️ DecryptionError (extends CryptoError) ⚠️ VerificationError (extends CryptoError)
🔧 FUNCTIONS 📊 DATA 🔢 VERSION 📅 DATE 👤 AUTHOR 📁 FILE

Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 16:22 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^