Skip to content

Instantly share code, notes, and snippets.

@X1ting
Created February 26, 2023 23:49
Show Gist options
  • Select an option

  • Save X1ting/6d814e5f9dd0cbc47f8eaed5f2ee65e0 to your computer and use it in GitHub Desktop.

Select an option

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

useeerfotopaketbot commented Jun 28, 2023

Copy link
Copy Markdown

Lihat🖼

@useeerfotopaketbot

Copy link
Copy Markdown

Foto paket

@useeerfotopaketbot

Copy link
Copy Markdown

Lihat🖼

@saviourini9

Copy link
Copy Markdown

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

Nmerey commented Aug 29, 2023

Copy link
Copy Markdown

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
Copy Markdown

@13714492Farz

Copy link
Copy Markdown

@mario-amazing

Copy link
Copy Markdown

Thanks a lot!!!!!!

@useeerfotopaketbot

Copy link
Copy Markdown

Lihat🖼
Uploading IMG_20231214_061934.jpg…

@useeerfotopaketbot

Copy link
Copy Markdown

Screenshot_20240107_225124
`

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