{"id":6915,"library":"tgcrypto","title":"TgCrypto","description":"TgCrypto is a cryptography library written in C as a Python extension, designed for high performance and portability. It serves as a crucial component for Pyrogram, implementing Telegram's required cryptographic algorithms: AES-256-IGE, AES-256-CTR, and AES-256-CBC. The latest version is 1.2.5, released in November 2022. However, its official GitHub repository was archived in December 2024, and the project is explicitly stated as no longer maintained or supported by its original authors.","status":"abandoned","version":"1.2.5","language":"en","source_language":"en","source_url":"https://github.com/pyrogram/tgcrypto","tags":["pyrogram","telegram","crypto","cryptography","encryption","mtproto","aes","c-extension","security","fast"],"install":[{"cmd":"pip install tgcrypto","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Runtime environment. Requires Python ~=3.7.","package":"Python","optional":false},{"reason":"Required for compiling the C extension if pre-built wheels are not available for your system (e.g., Visual C++ Build Tools on Windows, command-line developer tools on macOS, gcc/clang and python3-dev on Linux).","package":"C Build Tools","optional":true}],"imports":[{"symbol":"tgcrypto","correct":"import tgcrypto"}],"quickstart":{"code":"import os\nimport tgcrypto\n\n# Data for IGE mode must be padded to a multiple of the block size (16 bytes)\n# This example adds 7 bytes to demonstrate padding\ndata = os.urandom(10 * 1024 * 1024 + 7)\nkey = os.urandom(32) # AES-256 key (32 bytes)\niv = os.urandom(32)  # AES-256-IGE IV (32 bytes)\n\n# Pad with zeroes to be a multiple of 16 bytes\ndata += bytes(-len(data) % 16)\n\n# Perform IGE encryption and decryption\nige_encrypted = tgcrypto.ige256_encrypt(data, key, iv)\nige_decrypted = tgcrypto.ige256_decrypt(ige_encrypted, key, iv)\n\nassert data == ige_decrypted\nprint(\"IGE encryption/decryption successful!\")","lang":"python","description":"This quickstart demonstrates basic usage of the AES-256-IGE encryption and decryption functions, including the necessary data padding for IGE mode. Pyrogram will automatically use TgCrypto if installed."},"warnings":[{"fix":"Update function calls to use the `256` suffix (e.g., `tgcrypto.ige256_encrypt(...)`).","message":"API function names changed from `ige_encrypt`, `ige_decrypt`, `ctr_encrypt`, `ctr_decrypt` (in v1.0.x) to `ige256_encrypt`, `ige256_decrypt`, `ctr256_encrypt`, `ctr256_decrypt` (in v1.2.x). Code using older, non-suffixed function names will break.","severity":"breaking","affected_versions":"<1.2.0"},{"fix":"Users should be aware of the lack of ongoing maintenance. Consider migrating to actively maintained forks or alternatives if long-term support is critical, such as `TgCryptoX` or `tgcrypto-pyrofork`.","message":"The official `pyrogram/tgcrypto` GitHub repository was archived on December 23, 2024, and the project is explicitly stated as no longer maintained or supported by its original authors. This means no further updates, bug fixes, or security patches are expected from the original maintainers.","severity":"breaking","affected_versions":">=1.2.5"},{"fix":"Ensure the necessary build tools are installed for your operating system before attempting to `pip install tgcrypto`.","message":"Installing `tgcrypto` often requires C/C++ build tools on the system (e.g., Visual C++ Build Tools on Windows, Xcode Command Line Tools on macOS, `gcc`/`clang` and Python development headers (`python3-dev`) on Linux), especially if pre-compiled wheels are not available for your specific Python version and operating system. Installation may fail with compiler errors without these tools.","severity":"gotcha","affected_versions":"All"},{"fix":"Manually pad your data to a multiple of 16 bytes before calling `ige256_encrypt`. A common method is `data += bytes(-len(data) % 16)`.","message":"When using AES-256-IGE mode, the input `data` *must* be explicitly padded to a multiple of the block size (16 bytes) before encryption. The library does not handle padding automatically. Failure to pre-pad the data will result in a `ValueError` during encryption or incorrect decryption.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}