Skip to content
TGWAY
Channels & Bots STEP 95 / 99

Creating a Telegram Authorization Key: The Key Exchange

The MTProto authorization key is never sent: both sides compute it with Diffie-Hellman. The five steps, the checks you must not skip and temporary keys.

  • Applies toDevelopers
  • LevelL4
  • Reading time3 min
  • Verified

The short answer

  1. 1The authorization key never travels; both sides compute it with Diffie-Hellman.
  2. 2The server's public key built into the app proves you reached the real server.
  3. 3Skipping the checks on the received prime and values breaks all the encryption.
In this article
  1. What the authorization key is
  2. The exchange in five steps
  3. Skip the step 4 checks and everything fails
  4. One per data center, plus temporary keys
  5. FAQ
  6. At a glance

What the authorization key is

Every message a Telegram app exchanges with the server is encrypted with an authorization key (auth key). It is created together with the server the first time the app connects to a data center, and is rarely changed afterwards. The key itself never travels over the network: both sides compute the same value independently through a Diffie-Hellman key exchange (2048-bit).

TDLib and the official apps do all of this for you. This article explains what happens so you understand it. If you implement it yourself, follow the official steps and checks exactly; see client security guidelines.

The exchange in five steps

StepWhat happensWhy
1. HelloThe app sends a random value (nonce). The server returns its own random value, a number puzzle to solve and the fingerprint of its RSA public keyTies this exchange together so it cannot be mixed with another
2. Server checkThe app solves the puzzle (splitting a large number into two primes) and sends the answer with a new random value, encrypted with the server's public keyOnly the real server, holding the private key matching the public key built into the app, can read it. The puzzle is a light proof of work
3. IngredientsThe server sends, encrypted, the numbers for the exchange: a large prime, a generator and the server's public valueThe shared ingredients for the key
4. Check, then send your valueThe app must check the received numbers are safe, then sends its own public valueAccepting weak numbers lets someone else compute the key
5. Same key, confirmedBoth sides compute the same authorization key, and the server confirms with ok, retry or failThe key itself never crosses the network

At the end, the values used in the exchange also determine the first server salt. The salt is mixed into the encryption of later messages, and the server periodically sends new values.

Skip the step 4 checks and everything fails

One per data center, plus temporary keys

An authorization key is created separately for each data center; see data centers and _MIGRATE errors. On top of the long-lived permanent key, you can create temporary keys and bind them to it, so that even if the permanent key leaks later, past conversations cannot be decrypted (perfect forward secrecy). The official apps work this way.

A session file holding the authorization key is the account itself. Never let it leave the device; see MTProto at a glance.

FAQ

How is the Telegram authorization key created?

The app and server run a Diffie-Hellman exchange and each computes the same key; the key itself is never sent.

How does the app know it reached the real server?

It encrypts data with Telegram's RSA public key built into the app, which only the real server can decrypt.

What are temporary keys for?

Bound to the permanent key, they give perfect forward secrecy so a later leak cannot decrypt past traffic.

Sources

Summary

At a glance

Creating a Telegram Authorization Key: The Key Exchange — at a glance illustration
  1. 1Steps

    Hello, server check, ingredients, check and reply, confirm.

  2. 2Must check

    Safe prime, generator and value ranges.

  3. 3Keys

    One per data center; temporary keys give forward secrecy.

Share this guide

Send it to a friend who has the same question.

Telegram WhatsApp
More

Open on your phonePoint your phone camera here to open this guide.

Updated

Related articles

View all ›