TgCrypto
Fast and Portable Cryptography Extension Library for Pyrogram
What it is and what it does
TgCrypto is a C extension library that implements three AES-256 encryption modes required by Telegram's protocols: IGE (used in MTProto v2.0), CTR (used for CDN encrypted files), and CBC (used for encrypted passport credentials). It wraps low-level cryptographic operations in a minimal Python API of six functions—three encrypt/decrypt pairs—and is designed to be fast and portable across platforms.
The library is tightly coupled to Pyrogram, Telegram's Python client library, and is not a general-purpose cryptography tool. It has no runtime dependencies and installs via pre-built wheels for common platforms (Windows, macOS, Linux on x86 and ARM). However, the project is archived and abandoned: the last release was November 2022, and while the repository received a final commit in December 2024, no active maintenance or security updates should be expected.
Use it for:
- Encrypt and decrypt MTProto messages when building or extending Telegram client applications with Pyrogram.
- Handle CDN file encryption/decryption for Telegram file transfers in custom Telegram integrations.
- Implement Telegram Passport credential encryption for identity verification workflows in Telegram bots or clients.
- Stream large encrypted payloads using CTR mode with stateful encryption state across multiple chunks.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
TgCrypto provides fast C-based implementations of AES-256 encryption in IGE, CTR, and CBC modes, designed specifically for Telegram's MTProto protocol and related cryptographic needs.
Yes, if you are actively developing with Pyrogram and need Telegram's specific cipher implementations. No, if you are seeking general-purpose AES encryption or an actively maintained cryptography library—use a modern alternative like cryptography or PyCryptodome instead. The abandoned status means no security patches or Python version support beyond 3.11 should be expected.
Install
tgcrypto on PyPI
pip
pip install tgcryptouv
uv add tgcryptopoetry
poetry add tgcryptoInstalling TgCrypto
Before you install
Medium install friction due to compiled C extension requiring platform-specific wheels. The package is abandoned (last release November 2022, last commit December 2024), so no active maintenance or bug fixes should be expected.
License in practice
LGPLv3+ is copyleft: any derivative work must be licensed under compatible terms. Linking or bundling TgCrypto in a proprietary application requires careful license compliance review.
Quickstart
pip install tgcrypto
import tgcrypto
import os
data = os.urandom(32)
key = os.urandom(32)
iv = os.urandom(32)
data += bytes(-len(data) % 16) # Pad to 16-byte boundary
encrypted = tgcrypto.ige256_encrypt(data, key, iv)
decrypted = tgcrypto.ige256_decrypt(encrypted, key, iv)
Requires Python 3.7 or higher. IGE and CBC modes require data padded to a multiple of 16 bytes. CTR mode requires a state parameter (typically bytes(1) for initialization).
Verify before relying
- Whether the abandoned status and lack of recent maintenance pose security or compatibility risks for new Python versions beyond 3.11.
- Whether pre-built wheels cover all target platforms or if source compilation is needed on some systems.
Package facts
| License | LGPLv3+ (copyleft) |
| Python support | supports the current Python release (~=3.7) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 1,372 days since the last release |
| Last repo commit | (repository archived) |
| First released | |
| Downloads | 610,433/month — #5,766 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: TgCrypto-1.2.5-cp310-cp310-macosx_10_9_universal2.whl; TgCrypto-1.2.5-cp310-cp310-macosx_10_9_x86_64.whl; TgCrypto-1.2.5-cp310-cp310-macosx_11_0_arm64.whl; TgCrypto-1.2.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; TgCrypto-1.2.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl; TgCrypto-1.2.5-cp310-cp310-musllinux_1_1_i686.whl; TgCrypto-1.2.5-cp310-cp310-musllinux_1_1_x86_64.whl; TgCrypto-1.2.5-cp310-cp310-win32.whl; TgCrypto-1.2.5-cp310-cp310-win_amd64.whl; TgCrypto-1.2.5-cp311-cp311-macosx_10_9_universal2.whl; TgCrypto-1.2.5-cp311-cp311-macosx_10_9_x86_64.whl; TgCrypto-1.2.5-cp311-cp311-macosx_11_0_arm64.whl; TgCrypto-1.2.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; TgCrypto-1.2.5-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl; TgCrypto-1.2.5-cp311-cp311-musllinux_1_1_i686.whl; TgCrypto-1.2.5-cp311-cp311-musllinux_1_1_x86_64.whl; TgCrypto-1.2.5-cp311-cp311-win32.whl; TgCrypto-1.2.5-cp311-cp311-win_amd64.whl; TgCrypto-1.2.5-cp37-cp37m-macosx_10_9_x86_64.whl; TgCrypto-1.2.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Keywords: pyrogram, telegram, crypto, cryptography, encryption, mtproto, extension, library, aes
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
cryptgcryptg provides a native Python extension that…
permissive · top 15,000 on PyPI
oscryptooscrypto provides TLS sockets, key generation,…
permissive · top 1,000 on PyPI
PyrogramPyrogram is an asynchronous Python framework…
copyleft · top 15,000 on PyPI
unicryptoProvides a unified interface to cryptographic…
unclear · top 15,000 on PyPI
cryptoProvides command-line tools to encrypt and…
permissive · top 5,000 on PyPI
sslcryptoProvides AES, ECIES, and ECDSA cryptographic…
unclear · top 15,000 on PyPI
pytgcallsEnables Python bots to join Telegram voice…
copyleft · top 5,000 on PyPI
pyAesCryptEncrypts and decrypts files and binary streams…
permissive · top 15,000 on PyPI
aes-pkcs5Provides AES encryption and decryption with…
permissive · top 15,000 on PyPI
snitunSniTun is an SNI proxy with TCP multiplexer…
copyleft · top 15,000 on PyPI