Fast Telegram Crypto Library for Python
Project description
Fast Telegram Crypto Library for Python
Table of Contents
About
TgCrypto is a high-performance, easy-to-install Telegram Crypto Library written in C as a Python extension. TgCrypto is intended for Pyrogram [1] and implements the crypto algorithms Telegram requires, namely AES-IGE 256 bit (used in MTProto v2.0) and AES-CTR 256 bit (used for CDN encrypted files).
Installation
$ pip3 install --upgrade tgcrypto
Note: Being a C extension for Python, TgCrypto is an optional but highly recommended Pyrogram dependency; if TgCrypto is not detected in your system, Pyrogram will automatically fall back to the much slower PyAES and will show you a warning.
The reason about being an optional package is that TgCrypto requires some extra system tools in order to be compiled. The errors you receive when trying to install TgCrypto are system dependent, but also descriptive enough to understand what you should do next:
Windows: Install Visual C++ 2015 Build Tools.
macOS: A pop-up will automatically ask you to install the command line developer tools.
Linux: Install a proper C compiler (gcc, clang) and the Python header files (python3-dev).
Termux (Android): Install clang and python-dev packages.
API
TgCrypto API consists of these four functions:
def ige_encrypt(data: bytes, key: bytes, iv: bytes) -> bytes:
def ige_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes:
def ctr_encrypt(data: bytes, key: bytes, iv: bytes) -> bytes:
def ctr_decrypt(data: bytes, key: bytes, iv: bytes) -> bytes:
Usage
TgCrypto is as simple as this example:
import os
import tgcrypto
data = os.urandom(10 * 1024 * 1024) # 10 MB of random data
key = os.urandom(32) # Random Key
iv = os.urandom(32) # Random IV
ige_encrypted = tgcrypto.ige_encrypt(data, key, iv)
ige_decrypted = tgcrypto.ige_decrypt(ige_encrypted, key, iv)
assert data == ige_decrypted
Contribution
You are very welcome to contribute by either submitting pull requests or reporting issues/bugs as well as suggesting best practices, ideas, enhancements on both code and documentation. Any help is appreciated!
Feedback
Means for getting in touch:
License
Copyright (C) 2017-2018 Dan Tès <https://github.com/delivrance>
Licensed under the terms of the GNU Lesser General Public License v3 or later (LGPLv3+)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file TgCrypto-1.0.4.tar.gz
.
File metadata
- Download URL: TgCrypto-1.0.4.tar.gz
- Upload date:
- Size: 28.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bc9dc34f01858b558a1fe3a98ad6b810c14a21f7c3cb5a0a8973eb486e526f6 |
|
MD5 | eed947fd47ea1b5fc406a860bf44a355 |
|
BLAKE2b-256 | d48a23890ad6b0868e4f6882b196390ac0390e8eb873cebe39286a763f3bf31b |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 17.4 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e075b564034bcf05a04b44d25e319baae3a11b3ebc82cb8d086d2e9162aa737 |
|
MD5 | 08c7049c64d3024bd65251b8662a5aa9 |
|
BLAKE2b-256 | acb6d1a866bf5b9f52d236dc24fb8ef4da5663f5ef7ad0be8b6e80bb50d16984 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp36-cp36m-win32.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp36-cp36m-win32.whl
- Upload date:
- Size: 15.3 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7604496669aaded395e99e6c73b6939bacb6afdc18b8a652c6471b156cd64970 |
|
MD5 | 98bc4bdc446fc28fcc6745103272998f |
|
BLAKE2b-256 | 2d467ad311ad7daf5006fc9da5df61a95881ff932004dfbb00466f7571c09483 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 14.2 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5618d8cdf2cfb280512bcb9982868ecc6957c4236737e75b95fede0ebd6f16ac |
|
MD5 | af56c064f9c06be39363e368e797055f |
|
BLAKE2b-256 | 158d8fee5ee4535a79ef8d4d4418160b629beac07ff772ce1700e44023501019 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 14.5 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c1078bd6e58a10633dedabb19f5a2a152007ae909fee719ef9c9140fdb8fbb51 |
|
MD5 | e908542dcf9823528ea7135dc82378d8 |
|
BLAKE2b-256 | 9c7fab51d1f1a1acd77db974614dc59d2e2a759c60e854f57e967d9b028a1fe6 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
- Upload date:
- Size: 26.2 kB
- Tags: CPython 3.6m, macOS 10.10+ intel, macOS 10.10+ x86-64, macOS 10.6+ intel, macOS 10.9+ intel, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47ecf9febade70a77b711e5a62d090e8018dc49562a7416f383c9b3f663dc9b9 |
|
MD5 | 7457ea2efff33db808c28efa7f5768f4 |
|
BLAKE2b-256 | 11faff7e0cb7211f7b40499a345652c4c89b93279cf30cc88576334d451520d3 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp36-cp36m-linux_armv7l.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp36-cp36m-linux_armv7l.whl
- Upload date:
- Size: 24.2 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32489ff2f317044ba49ce22d0b9973c4b619a8dfcb2e74bba5069d7fb6974cc1 |
|
MD5 | fe0624f9c8721691eeb8ec9b614d37db |
|
BLAKE2b-256 | 735b740cccc96dd79b8a3a16cd9eeb095a5246031ff8370e484732641079cde3 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 17.4 kB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fb64417dcd224166b1ff5081767b6fa28d7b6f029a5e7ff4771555d2674bb7cd |
|
MD5 | c3ca5adf6bf4d36a1e30423d4cfa7f7a |
|
BLAKE2b-256 | 05b874d51dce20b6d21b1bc2bd91453b305adc4a8af4789d908e6018e6cac885 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp35-cp35m-win32.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp35-cp35m-win32.whl
- Upload date:
- Size: 15.3 kB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db8d3ab4ad4b140e7894e049941babcced50e4dec202151a2d056ff1b8963877 |
|
MD5 | f7459327c5e6055c2845bf8a81d5e6f1 |
|
BLAKE2b-256 | 07aad64cff780d1fc2fe3d6b74c64f2d630634129cff144ee74e1adc675c0b84 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 14.2 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0336274ce29b9a2f6e1fcd0668520371bf5f02fdf642edfd3fbaadf1757933d2 |
|
MD5 | 1f0b6f0dbd6b63326f5827dd6ac9a69d |
|
BLAKE2b-256 | 4f9a4640b7ac09302be4ce3f6039badfda559fe1dc8a332b1b89211212668331 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp35-cp35m-manylinux1_i686.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp35-cp35m-manylinux1_i686.whl
- Upload date:
- Size: 14.5 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 066c5b05d2fb479a2178877c20da4ef19d09cd0612e9d4f1e770b2561917e98b |
|
MD5 | a7fbc6da9987d41fe667e7bbc86ff587 |
|
BLAKE2b-256 | 39a7544f70c0a1ae9b03b1b9a374acb3483c4ee844b3c8b755c1465bcc071df0 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
- Upload date:
- Size: 26.2 kB
- Tags: CPython 3.5m, macOS 10.10+ intel, macOS 10.10+ x86-64, macOS 10.6+ intel, macOS 10.9+ intel, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd973b900c756d8daa64ba9e4b78f6cfebb00079a9030e047784dab3e7665d4b |
|
MD5 | c398896a064c9fbc14bce337800ef11b |
|
BLAKE2b-256 | a7eda8f84b5d3d255c6a8613f5dd381b8877d1e5a094041271e914622ddc3304 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp35-cp35m-linux_armv7l.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp35-cp35m-linux_armv7l.whl
- Upload date:
- Size: 29.9 kB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e7429e2c1544be03ba26a52a9d06b62e7d73efe28be40034a9e0fa7627b7af84 |
|
MD5 | 7d1a3c9f03ad747ea5671e24a8f87c34 |
|
BLAKE2b-256 | 124741c37348d74c775c7569b99259b42d6d12da6c31ca7b473640eed3a0f90b |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp34-cp34m-win_amd64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp34-cp34m-win_amd64.whl
- Upload date:
- Size: 15.4 kB
- Tags: CPython 3.4m, Windows x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d94e68e145eebd408d66fbe82d293cc442884943548783ed343ee86e19ca31d |
|
MD5 | 8369bd91efdc68dbcf66d2fe98950b26 |
|
BLAKE2b-256 | 0cf4923c73b95a47190cf9e6ad95da7077f9e7a2d78f2afaddde1ac71d36bb88 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp34-cp34m-win32.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp34-cp34m-win32.whl
- Upload date:
- Size: 15.2 kB
- Tags: CPython 3.4m, Windows x86
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ff7900f28dcace9d20892976abba653b231901396e800cb1c3289d8abd3b193 |
|
MD5 | a94164d00225fe3d4c442ca4645d89ef |
|
BLAKE2b-256 | 5d96bb652d19c5f2d10161d13fe3297f516a6be9ad3bf5e4a41bced7b2ebd48c |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp34-cp34m-manylinux1_x86_64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp34-cp34m-manylinux1_x86_64.whl
- Upload date:
- Size: 14.1 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41ba3bf978970ac5425a6a1789811df65581f5746f71242013b9b4eda4d3db06 |
|
MD5 | 0f7c5ffc8772950288c6d54755d8ca54 |
|
BLAKE2b-256 | e7639c146accdb9d4d2d800f561409331c2a62b1417376516ab761041554e68d |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp34-cp34m-manylinux1_i686.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp34-cp34m-manylinux1_i686.whl
- Upload date:
- Size: 14.4 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d64c447edc3d83c5541a2897a68ba8a0652b43c385271e26a4b37e5f5fac490 |
|
MD5 | c546789158c029d89d763df361e4c1b9 |
|
BLAKE2b-256 | c674dd6be339564a50370418c84158d3279ce589ac806b778d0d2d149031854d |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
- Upload date:
- Size: 26.2 kB
- Tags: CPython 3.4m, macOS 10.10+ intel, macOS 10.10+ x86-64, macOS 10.6+ intel, macOS 10.9+ intel, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6afe7e59d73d279805bf20530d388ded1d01792fe53df05a5389ebf33855a680 |
|
MD5 | 614472f74d26f7c0ab60c4ecca8b933e |
|
BLAKE2b-256 | 7c9257d07b149dcad3e16c019500946ad97d2aa7c298ba5dd019d85b93e72c73 |
Provenance
File details
Details for the file TgCrypto-1.0.4-cp34-cp34m-linux_armv7l.whl
.
File metadata
- Download URL: TgCrypto-1.0.4-cp34-cp34m-linux_armv7l.whl
- Upload date:
- Size: 29.6 kB
- Tags: CPython 3.4m
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1febaf94a30a677b1f4f7171407ccf1c2c327ac99dff353a1d0355336b7b470 |
|
MD5 | 5cbcc4d7cbcd2d5d6b67d7cb290f1d3d |
|
BLAKE2b-256 | f2d46765012fa7029c61bf9ca683930c351b41b5f4260cdcf88198fdf5ed95a0 |