Skip to content

Instantly share code, notes, and snippets.

@X1ting
Created February 26, 2023 23:49
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save X1ting/6d814e5f9dd0cbc47f8eaed5f2ee65e0 to your computer and use it in GitHub Desktop.
Save X1ting/6d814e5f9dd0cbc47f8eaed5f2ee65e0 to your computer and use it in GitHub Desktop.
Check telegram auth token
data = {
auth_date: DATE,
first_name: "NAME",
hash: "HASH",
id: ID,
last_name: "SURNAME",
photo_url: "PHOTO",
username: "USERNAME"
}
token = "YOUR_TOKEN"
check_data = data.except(:hash).sort.to_h.map { |k,v| "#{k}=#{v}"}.join("\n")
hashed_token = Digest::SHA256.digest(token)
hash = OpenSSL::HMAC.hexdigest("SHA256", hashed_token, check_data)
puts data[:hash] == hash
@useeerfotopaketbot
Copy link

useeerfotopaketbot commented Jun 28, 2023

Lihat🖼

@useeerfotopaketbot
Copy link

Foto paket

@useeerfotopaketbot
Copy link

Lihat🖼

@saviourini9
Copy link

data = {
auth_date: DATE,
first_name: "NAME",
hash: "HASH",
id: ID,
last_name: "SURNAME",
photo_url: "PHOTO",
username: "USERNAME"
}

token = 6259800315:AAEfZ7q_VymgLq55JNOjCjovkRFUQA_zh6w
check_data = data.except(:hash).sort.to_h.map { |k,v| "#{k}=#{v}"}.join("\n")
hashed_token = Digest::SHA256.digest(token)
hash = OpenSSL::HMAC.hexdigest("SHA256", hashed_token, check_data)
puts data[:hash] == hash

@Nmerey
Copy link

Nmerey commented Aug 29, 2023

Keep in mind that when you receive data as params it will not be symbolized as shown above. It will be instance of Parameters class which will not work with snippet above. You will have to permit all params sent by Telegram and you will get "string" => "string" hash data so

check_data = data.except(:hash)... should be check_data = data.except('hash')...

P.S
Also, OpenSSL::HMAC.hexdigest first param should be instance of OpenSSL::Digest.new('sha256') class instead of just a string "SHA256"

@13714492Farz
Copy link

@mario-amazing
Copy link

Thanks a lot!!!!!!

@useeerfotopaketbot
Copy link

Lihat🖼
Uploading IMG_20231214_061934.jpg…

@useeerfotopaketbot
Copy link

Screenshot_20240107_225124
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment