skip to Main Content

I’ve got this instrunctions from Telegram documenation
enter image description here

but how to write it in PHP?

I tried this one:

if (pack("H*",hash_hmac('sha256',$string, $secret_key)) == $info['hash']) {

but unsuccesfully.. any ideas how to apply this code in php?

2

Answers


  1. Chosen as BEST ANSWER

    I figured it out..

    secret_key = HMAC_SHA256(<bot_token>, "WebAppData")
    

    php equal is:

    $secret_key = hash_hmac('sha256',$bot_token, 'WebAppData', true);
    

    and

    hex(HMAC_SHA256(data_check_string, secret_key))
    

    it is just:

    hash_hmac('sha256',$dataCheckString, $secret_key);
    

  2. Does this accurately reflect your intent?

    if(hach_hmac("sha256", $data_check_string, $secret_key) === $info['hash']){
      // data is from Telegram
    }
    

    If the third parameter of the hash_hmac function is not provided or is set to false, it will return a lowercase hexadecimal value. More information can be found at https://www.php.net/manual/ja/function.hash-hmac.php

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search