TgCrypto

1.2.5 · abandoned · verified Wed Apr 15

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.

Warnings

Install

Imports

Quickstart

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!")

view raw JSON →