Home >Backend Development >PHP Tutorial >How to Generate a Telegram Authorization Key in VB.Net?
So far I have been able to implement the telegram authorization completely, but not in your requested language - PHP, I used vb.Net. However, I believe the same logic should apply.
Creating a Telegram Authorization Key
Telegram API is no walk in the park. Studying existing src code could be quite daunting (IMHO). Hence my approach was to study the online API documentation and implement the sample-auth_key outlined in the links below.
https://core.telegram.org/mtproto/auth_key
https://core.telegram.org/mtproto/samples-auth_key
What this approach will give you is a better understanding and introduction to the primitives used throughout Telegram API, and possibly help you start organizing your own set of functions and routines to handle which you will need for the next steps - implementing other features of the API, since generating an AuthKey is just the beginning.
Step 1
All Communication is via TCP - Once you have obtained a unique api_id (https://core.telegram.org/api/obtaining_api_id#obtaining-api-id) you will find the following IP advertised for use in testing: 149.154.167.40:433 The api_id is not required at this point for generating an AuthKey
Setup your preferred method of Send/Receive TCP processing Loop
what I have is a private SendData that simply sends a bytes to a live socket connected to the give IP address above
<๐๐๐><p>End Sub</p><p>Private Sub ReadData(Optional wait As Integer = 0)</p><๐๐๐><p>End Sub</p><p>Private Sub IO_Handler(sender As Object, e As SocketAsyncEventArgs)</p><๐๐๐><p>End Sub</p><p>Private Sub HandleData(e As SocketAsyncEventArgs)</p><๐๐๐><p>End Sub<br>
Finally for this step, we need a TcpPack() method which helps us pad our data in the format Telegram expects - see code below with comments
<๐๐๐><p>End Function<br>
STEP 2
With the basic TCP send/receive routines setup, we can start preparing data packets to send to telegram and have sub routines for handling the specific responses received - ProcessResponse(data)
What we need to understand next is the fact that Telegram handles 2 broad categories of messages -
Unencrypted - https://core.telegram.org/mtproto/description#unencrypted-message
These are plain text messages with their auth_key_id =0 generating an AuthKey uses this type of message throughout
Encrypted - https://core.telegram.org/mtproto/description#encrypted-message-encrypted-data
All further communication with Telegram Servers will be via encrypted messages
I choose to have two classes to encapsulate both message types. I can then have two Send(m) methods that handles each type
<๐๐๐><p>End Sub</p><p>Private Sub Send(m As EncryptedMessage)</p><๐๐๐><p>End Sub<br>
For now only UnencryptedMessage is required
The above is the detailed content of How to Generate a Telegram Authorization Key in VB.Net?. For more information, please follow other related articles on the PHP Chinese website!