Registry / auth-security / tgcrypto

tgcrypto

JSON →
library1.2.5pypypi✓ verified 86d ago

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.

pip install tgcrypto
INSTALL
IMPORT
SIG · TGCRYPTO
T
tgcrypto
auth-securitypythonv1.2.5
Install
1.8s avg
Import
Disk
19MB
Pass rate
6/ 10
Env Coverage6 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.5 · pip install
no network on importno background threads
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
glibc
py 3.10
✓ —
✓ 1.68s
py 3.11
✓ —
✓ 1.78s
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 1.98s
19MB installed
● package 19MB
Code
Verified usage

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

tgcrypto
import tgcrypto

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.

import os import tgcrypto # Data for IGE mode must be padded to a multiple of the block size (16 bytes) # This example adds 7 bytes to demonstrate padding data = os.urandom(10 * 1024 * 1024 + 7) key = os.urandom(32) # AES-256 key (32 bytes) iv = os.urandom(32) # AES-256-IGE IV (32 bytes) # Pad with zeroes to be a multiple of 16 bytes data += bytes(-len(data) % 16) # Perform IGE encryption and decryption ige_encrypted = tgcrypto.ige256_encrypt(data, key, iv) ige_decrypted = tgcrypto.ige256_decrypt(ige_encrypted, key, iv) assert data == ige_decrypted print("IGE encryption/decryption successful!")
Debug
Known issues
breakingAPI 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.
fix
Update function calls to use the `256` suffix (e.g., `tgcrypto.ige256_encrypt(...)`).
affects: <1.2.0
breakingThe 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.
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`.
affects: >=1.2.5
gotchaInstalling `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.
fix
Ensure the necessary build tools are installed for your operating system before attempting to `pip install tgcrypto`.
affects: All
gotchaWhen 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.
fix
Manually pad your data to a multiple of 16 bytes before calling `ige256_encrypt`. A common method is `data += bytes(-len(data) % 16)`.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tgcrypto'
The `tgcrypto` package is either not installed in the current Python environment or its installation failed due to missing build dependencies.
fix
pip install tgcrypto
error: Microsoft Visual C++ 14.0 is required.
`tgcrypto` is a C extension that requires a C++ compiler to build from source, and the necessary Microsoft Visual C++ build tools are not installed on the Windows system.
fix
Download and install the "Build Tools for Visual Studio" from Microsoft's website, ensuring to select the "Desktop development with C++" workload during installation.
error: command 'gcc' failed
`tgcrypto` is a C extension that requires a C compiler (like GCC on Linux or Clang via Xcode on macOS) to build from source, but it is not found or not properly configured on the system.
fix
On Linux, run `sudo apt-get install build-essential`. On macOS, run `xcode-select --install`.
RuntimeError: Cryptography is not available.
When used with Pyrogram, this error occurs because `tgcrypto` (or another cryptography backend) is not installed or could not be imported by Pyrogram.
fix
Ensure `tgcrypto` is successfully installed by running `pip install tgcrypto`. If installation fails, address underlying compiler or build dependency issues first.
Upgrade
Version history
1.2.5latest on PyPI · released Nov 11, 2022
Audit
Dependencies
PythonrequiredRuntime environment. Requires Python ~=3.7.
C Build ToolsoptionalRequired 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).
Agent activity
34 hits · last 30 days
node
32
OpenAI (training)
1
Resources