Cryptg

raw JSON →
0.6.0 verified Mon Apr 27 auth: no python

Cryptographic utilities for Telegram, implementing MTProto encryption primitives (AES-IGE, AES-CTR, IGE mode, key generation). Version 0.6.0, supports Python >=3.11, actively maintained.

pip install cryptg
error ImportError: cannot import name 'ige_encrypt' from 'cryptg'
cause The function was renamed to `aes_ige_encrypt` in newer versions.
fix
Use from cryptg import aes_ige_encrypt
error ValueError: key must be 32 bytes long
cause Supplied key size is not 32 bytes (AES-256 requirement).
fix
Use generate_key() or provide exactly 32 bytes.
error cryptg requires Python >=3.11
cause Trying to install cryptg 0.6.0 on an older Python version.
fix
Upgrade to Python 3.11+ or install cryptg<0.6.0 (e.g., pip install cryptg==0.5.4).
gotcha cryptg is low-level; do NOT use for general encryption. Designed specifically for Telegram MTProto protocol. Using it for other purposes may lead to security issues.
fix Use libraries like cryptography or PyCryptodome for general encryption.
breaking In version 0.6.0, Python version requirement changed to >=3.11. Older Python versions are no longer supported.
fix Upgrade Python to 3.11+ or pin cryptg<0.6.0.
deprecated Legacy function names like `ige_encrypt` and `ige_decrypt` are deprecated; use `aes_ige_encrypt`/`aes_ige_decrypt` instead.
fix Replace with `aes_ige_encrypt` and `aes_ige_decrypt`.
gotcha Key and IV sizes are fixed: 32 bytes for AES-256, 32 bytes for IV in IGE. Using wrong sizes will raise an error.
fix Use `generate_key()` to get a properly sized key, and ensure IV is 32 bytes.

Basic IGE encryption/decryption with random key

from cryptg import encrypt_ige, decrypt_ige, generate_key
key = generate_key()  # 32 bytes for AES-256
iv = bytes(32)
plaintext = b'Hello Telegram'
encrypted = encrypt_ige(plaintext, key, iv)
decrypted = decrypt_ige(encrypted, key, iv)
print(decrypted)