# TGBACK-X — a library for making Telegram account backups
###### _[Check out the GUI implementation - XQt!](https://github.com/NotStatilko/tgback-x-qt)_
**TGBACK-X** is a little library which you can utilize to create an **encrypted backup of your Telegram account**. If you've been around here before then you probably heard about my old project called [TGBACK](https://github.com/NotStatilko/tgback) (without *X*). Actually, this library is an **implementation revisit** of the same concept with just about the same purpose.
The difference between the *old TGBACK* and *X version* (except completely different backup structure) is that this repository is **strictly Python library for devs** and doesn't have any App implementation (like Command line app that old *TGBACK* have). However most importantly, **this version doesn't create any backup files** (hence the *X* in name). Instead, it relies on the *Providers* — **third-party services that we use to store encrypted backup data.**
## **Idea behind:**
1. User type password or **we generate random N (default 8) mnemonic words**;
2. **We feed password to Scrypt** (1GB from defaults), obtain *Scrypt key*;
3. We make **(hash)** a unique *KeyID* from *Scrypt key* material;
4. We ask for Telegram login credentials, log into account;
5. We take account's **session** and construct a backup data;
6. We **encrypt backup data** with one of *Cryptography Protocol*;
7. We **store the encrypted backup data on Provider server by KeyID**.
In that way, User will be able to get Session only by typing secret Phrase. Obviously, this approach may impose some risks — anyone who will be able to type the same Phrase will obtain a full access to account. User should **treat its Phrase like Bitcoin seed phrase** and **never** use *X* version on a compromised Computer, e.g, with malwares / other programs that can record keyboard or screen.
Telegram session is no-special in TGBACK-X and can be killed at any time through Telegram Settings —> Devices or directly from backup data by itself. Disconnected Session is a useless pile of encoded bytes. If you feel that your Phrase may be compromised — **destroy session immediately**. You can always create a different one. Different backups keep different sessions, so they wouldn't be connected at all.
## **Default approach:**
**Default** (and currently only one implemented here) *Provider* is a `TelegramChannel`. That is, we keep your encrypted Telegram data inside Telegram! The *KeyID* would be a *Channel public link*, and *Backup data* would be regular message. We utilize interesting Telegram feature — any **public** Telegram channel can be previewed in Browser without login. [**See this for example**](https://t.me/s/X3KEK3ELMZDDJ5KXEIJMEH65L4CJCMAY) — is a backup that you can make with `TelegramChannel`. We fetch backup data (`TelegramChannel` use `JSON_AES_CBC_UB64` crypto protocol) through http requests, decrypt and give Session to User.
## Welcome, developers
I (hope I) made **TGBACK-X** library modular, so you can create your own *Provider* / *Protocol* classes. Currently there is no documentation, but I tried to describe everything in Docstrings. You can refer to them and check how default classes are implemented for basic understanding. While I don't think that there is any sense in adding new cryptography *Protocol* (`JSON_AES_CBC_UB64` seems about enough), different *Provider* would be interesting to see.
### Install
```
pip install tgback-x
```
### Quick Example
**Store Session (Create backup)**
```python3
import tgback_x
import phrasegen
API_ID: int=1234567 # Obtain at my.telegram.org
API_HASH: str='00000000000000000000000000000000'
client = tgback_x.TelegramClient(
session=tgback_x.StringSession(),
api_id=API_ID,
api_hash=API_HASH
)
# You can also Sign-In with the .send_code_request() and
# the .sign_in() method, as this is just a quick example. See
# docs.telethon.dev/en/stable/quick-references/client-reference.html
client.start()
generator = phrasegen.Generator()
phrase = generator.en.generate()
print('Your phrase is', phrase)
# Customizable. Unique Salt is highly recommendable.
key = tgback_x.crypto.make_scrypt_key(phrase.encode())
provider = tgback_x.providers.TelegramChannel()
provider.store(tgback_x.crypto.Key(key), client)
```
**Get Session (Load backup)**
```python3
import tgback_x
phrase = b'here comes your phrase dio ozzy'
key = tgback_x.crypto.make_scrypt_key(phrase)
provider = tgback_x.providers.TelegramChannel()
client = provider.get(tgback_x.crypto.Key(key))
print(client.get_me())
```
**Destroy Session & Backup**
```python3
import tgback_x
phrase = b'here comes your phrase dio ozzy'
key = tgback_x.crypto.make_scrypt_key(phrase)
provider = tgback_x.providers.TelegramChannel()
provider.destroy(tgback_x.crypto.Key(key))
```
Raw data
{
"_id": null,
"home_page": "https://github.com/NonProjects/tgback-x",
"name": "tgback-x",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "Telegram, Backup, Account, Non-official",
"author": null,
"author_email": "thenonproton@pm.me",
"download_url": "https://files.pythonhosted.org/packages/0e/81/0e5de1b7e3e08c5600ee909948229878c23297280d6ae77c26b88ae3e611/tgback_x-1.1.tar.gz",
"platform": null,
"description": "# TGBACK-X \u2014 a library for making Telegram account backups\n\n###### _[Check out the GUI implementation - XQt!](https://github.com/NotStatilko/tgback-x-qt)_\n\n**TGBACK-X** is a little library which you can utilize to create an **encrypted backup of your Telegram account**. If you've been around here before then you probably heard about my old project called [TGBACK](https://github.com/NotStatilko/tgback) (without *X*). Actually, this library is an **implementation revisit** of the same concept with just about the same purpose.\n\nThe difference between the *old TGBACK* and *X version* (except completely different backup structure) is that this repository is **strictly Python library for devs** and doesn't have any App implementation (like Command line app that old *TGBACK* have). However most importantly, **this version doesn't create any backup files** (hence the *X* in name). Instead, it relies on the *Providers* \u2014 **third-party services that we use to store encrypted backup data.**\n\n## **Idea behind:**\n\n1. User type password or **we generate random N (default 8) mnemonic words**;\n2. **We feed password to Scrypt** (1GB from defaults), obtain *Scrypt key*;\n3. We make **(hash)** a unique *KeyID* from *Scrypt key* material;\n4. We ask for Telegram login credentials, log into account;\n5. We take account's **session** and construct a backup data;\n6. We **encrypt backup data** with one of *Cryptography Protocol*;\n7. We **store the encrypted backup data on Provider server by KeyID**.\n\nIn that way, User will be able to get Session only by typing secret Phrase. Obviously, this approach may impose some risks \u2014 anyone who will be able to type the same Phrase will obtain a full access to account. User should **treat its Phrase like Bitcoin seed phrase** and **never** use *X* version on a compromised Computer, e.g, with malwares / other programs that can record keyboard or screen.\n\nTelegram session is no-special in TGBACK-X and can be killed at any time through Telegram Settings \u2014> Devices or directly from backup data by itself. Disconnected Session is a useless pile of encoded bytes. If you feel that your Phrase may be compromised \u2014 **destroy session immediately**. You can always create a different one. Different backups keep different sessions, so they wouldn't be connected at all.\n\n## **Default approach:**\n\n**Default** (and currently only one implemented here) *Provider* is a `TelegramChannel`. That is, we keep your encrypted Telegram data inside Telegram! The *KeyID* would be a *Channel public link*, and *Backup data* would be regular message. We utilize interesting Telegram feature \u2014 any **public** Telegram channel can be previewed in Browser without login. [**See this for example**](https://t.me/s/X3KEK3ELMZDDJ5KXEIJMEH65L4CJCMAY) \u2014 is a backup that you can make with `TelegramChannel`. We fetch backup data (`TelegramChannel` use `JSON_AES_CBC_UB64` crypto protocol) through http requests, decrypt and give Session to User.\n\n## Welcome, developers\n\nI (hope I) made **TGBACK-X** library modular, so you can create your own *Provider* / *Protocol* classes. Currently there is no documentation, but I tried to describe everything in Docstrings. You can refer to them and check how default classes are implemented for basic understanding. While I don't think that there is any sense in adding new cryptography *Protocol* (`JSON_AES_CBC_UB64` seems about enough), different *Provider* would be interesting to see.\n\n### Install\n```\npip install tgback-x\n```\n\n### Quick Example\n\n**Store Session (Create backup)**\n\n```python3\nimport tgback_x\nimport phrasegen\n\nAPI_ID: int=1234567 # Obtain at my.telegram.org\nAPI_HASH: str='00000000000000000000000000000000'\n\nclient = tgback_x.TelegramClient(\n session=tgback_x.StringSession(),\n api_id=API_ID,\n api_hash=API_HASH\n)\n# You can also Sign-In with the .send_code_request() and\n# the .sign_in() method, as this is just a quick example. See\n# docs.telethon.dev/en/stable/quick-references/client-reference.html\nclient.start()\n\ngenerator = phrasegen.Generator()\nphrase = generator.en.generate()\n\nprint('Your phrase is', phrase)\n\n# Customizable. Unique Salt is highly recommendable.\nkey = tgback_x.crypto.make_scrypt_key(phrase.encode())\n\nprovider = tgback_x.providers.TelegramChannel()\nprovider.store(tgback_x.crypto.Key(key), client)\n```\n\n**Get Session (Load backup)**\n```python3\nimport tgback_x\n\nphrase = b'here comes your phrase dio ozzy'\nkey = tgback_x.crypto.make_scrypt_key(phrase)\n\nprovider = tgback_x.providers.TelegramChannel()\nclient = provider.get(tgback_x.crypto.Key(key))\n\nprint(client.get_me())\n```\n\n**Destroy Session & Backup**\n```python3\nimport tgback_x\n\nphrase = b'here comes your phrase dio ozzy'\nkey = tgback_x.crypto.make_scrypt_key(phrase)\n\nprovider = tgback_x.providers.TelegramChannel()\nprovider.destroy(tgback_x.crypto.Key(key))\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "tgback-x \u2014 a library for making Telegram account backups",
"version": "1.1",
"project_urls": {
"Download": "https://github.com/NonProjects/tgback-x/archive/refs/tags/v1.1.tar.gz",
"Homepage": "https://github.com/NonProjects/tgback-x"
},
"split_keywords": [
"telegram",
" backup",
" account",
" non-official"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "05d78a025838ed4bbeb69186f27ad06e17b9010798aaf2f6d12d277ef12ab5d7",
"md5": "e31c82df2127f83e9744580cc3e4298b",
"sha256": "19fdddee3050ee7deb26879b1e0017c57e70f3ceaebf0faa655ae0f661a65dc9"
},
"downloads": -1,
"filename": "tgback_x-1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e31c82df2127f83e9744580cc3e4298b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 13306,
"upload_time": "2025-01-28T18:13:38",
"upload_time_iso_8601": "2025-01-28T18:13:38.053356Z",
"url": "https://files.pythonhosted.org/packages/05/d7/8a025838ed4bbeb69186f27ad06e17b9010798aaf2f6d12d277ef12ab5d7/tgback_x-1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0e810e5de1b7e3e08c5600ee909948229878c23297280d6ae77c26b88ae3e611",
"md5": "85d82f40ea2933796ff1e0d64e6591a2",
"sha256": "45a5eb4ed9e30fcf71eb49989dd85fa517a978d8c4d574e845508899fb5583da"
},
"downloads": -1,
"filename": "tgback_x-1.1.tar.gz",
"has_sig": false,
"md5_digest": "85d82f40ea2933796ff1e0d64e6591a2",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 13568,
"upload_time": "2025-01-28T18:13:40",
"upload_time_iso_8601": "2025-01-28T18:13:40.030830Z",
"url": "https://files.pythonhosted.org/packages/0e/81/0e5de1b7e3e08c5600ee909948229878c23297280d6ae77c26b88ae3e611/tgback_x-1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-28 18:13:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "NonProjects",
"github_project": "tgback-x",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tgback-x"
}