Registry / auth-security / m2crypto

m2crypto

JSON →
library0.48.0pypypiunverified

M2Crypto is a comprehensive cryptography and SSL toolkit for Python, acting as a wrapper around the well-established OpenSSL library via SWIG. It provides functionalities for RSA, DSA, DH, HMACs, message digests, symmetric ciphers including AES, and TLS for client and server implementations. The library is currently in maintenance mode, with its developers recommending migration to more modern alternatives like PyCA/cryptography. The latest version, 0.47.0, was released on February 8, 2026. While not on a fixed schedule, releases appear periodically.

pip install M2Crypto
INSTALL
IMPORT
SIG · M2CRYPTO
M
m2crypto
auth-securitypythonv0.48.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v? · pip install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
build_error
glibc
py 3.103.920 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RSA
from M2Crypto import RSA
import M2Crypto.RSA
Many M2Crypto modules are designed to be imported directly from the M2Crypto package, rather than as submodules, to ensure attributes are correctly resolved.
SSL
from M2Crypto import SSL
import M2Crypto.SSL
Similar to RSA, direct import from M2Crypto is the standard and recommended practice.
X509
from M2Crypto import X509
import M2Crypto.X509
Older patterns like `import M2Crypto` followed by `M2Crypto.X509` may lead to 'M2Crypto has no attributes' errors in some contexts, especially when not fully installed or with specific runtime environments.

This quickstart demonstrates basic RSA key generation, encryption, and decryption using M2Crypto. It generates a 2048-bit RSA key pair, encrypts a simple message using PKCS1 OAEP padding with the public key, and then decrypts it using the private key. Note that messages should be bytes for cryptographic operations.

from M2Crypto import RSA # Generate RSA key pairs rsa_key = RSA.gen_key(2048, 65537) # Message to encrypt message = b"Hello, M2Crypto!" # Encrypt a message using the public key ciphertext = rsa_key.public_encrypt(message, RSA.pkcs1_oaep_padding) print(f"Ciphertext: {ciphertext.hex()}") # Decrypt the message using the private key decrypted = rsa_key.private_decrypt(ciphertext, RSA.pkcs1_oaep_padding) print(f"Decrypted: {decrypted.decode()}")
Debug
Known issues
deprecatedM2Crypto is officially in maintenance mode. Developers recommend migrating to actively developed and more modern alternatives like PyCA/cryptography for new projects or existing applications.
fix
For new projects, consider PyCA/cryptography (`pip install cryptography`). For existing projects, consult M2Crypto's documentation on migration paths.
affects: All versions
breakingVersion 0.47.0 (and newer) no longer includes SWIG generated files in the distribution. This means `swig` must be installed on your system when installing M2Crypto, with SWIG 4.0+ being required for Python 3.12+.
fix
Ensure SWIG (version 4.0 or newer for Python 3.12+) is installed globally or in your build environment before running `pip install M2Crypto`.
affects: 0.47.0+
breakingAll support for Python's `asyncore` module, `contrib/dispatcher.py`, `M2Crypto/SSL/ssl_dispatcher.py`, and `ZServerSSL` has been removed in M2Crypto 0.47.0 to align with its removal in Python 3.12+.
fix
Applications relying on `asyncore` or related M2Crypto modules for asynchronous SSL operations must refactor their code to use more modern asynchronous frameworks (e.g., `asyncio`) or different SSL libraries if targeting M2Crypto 0.47.0+ with Python 3.12+.
affects: 0.47.0+
gotchaInstallation of M2Crypto often requires system-level development headers for OpenSSL and the SWIG utility, which can be challenging, especially on Windows or minimal Linux environments.
fix
Install `openssl-devel` (or equivalent) and `swig` via your system's package manager before attempting `pip install M2Crypto`. On Windows, manual compilation or pre-built wheels from other projects might be necessary if `pip install` fails.
affects: All versions
gotchaM2Crypto, due to its direct interfacing with OpenSSL's C API, can encounter memory leaks or segmentation faults if objects are not freed correctly across the Python/C boundary, or due to incompatibilities with different OpenSSL versions.
fix
Handle M2Crypto objects carefully, ensuring proper lifecycle management. Keep OpenSSL and M2Crypto versions compatible. Regularly test your application for memory leaks, especially when dealing with high-volume cryptographic operations.
affects: All versions
Upgrade
Version history
0.48.0latest on PyPI · released May 23, 2026
Audit
Dependencies
opensslrequiredM2Crypto is a wrapper around the OpenSSL library and requires it for core cryptographic functions.
swigrequiredM2Crypto uses SWIG (Simplified Wrapper and Interface Generator) to create its Python interface from C/C++ code. SWIG 4.0+ is required for M2Crypto 0.47.0+.
packagingrequiredUsed for version parsing and compatibility checks.
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
3
Resources
m2crypto — pip install m2crypto · libregistry