skip to Main Content

I need to write THIS in php

https://cryptii.com/pipes/QiZmdA

I have tried those but don’t produce the same result

<?php
    echo hash_hmac('sha1', '002590cd26da', "8544e3b47eca58f9583043f8");
 echo var_dump(hash_hmac("sha1", "002590cd26da", pack("H*", "8544e3b47eca58f9583043f8")));
?>

what am i doing wrong ?

Thanks in advance

2

Answers


  1. Chosen as BEST ANSWER

    thanks figures out it will also work like this

    $t=hash_hmac('sha1', pack("H*", $macaddr), pack("H*", '8544e3b47eca58f9583043f8'));

    cheers


  2. You need convert the hex string to binary first then use function hash_hmac with ‘true’ parameter to get binary output and last,convert the binary HMAC to a hex string.

    Here fixed example code :

    <?php
    $data = hex2bin("002590cd26da"); // Convert the hex string to binary
    $key = hex2bin("8544e3b47eca58f9583043f8"); // Convert the hex key to binary
    
    $hmac = hash_hmac('sha1', $data, $key, true); // Use 'true' to get binary output
    $hmac_hex = bin2hex($hmac); // Convert the binary HMAC to a hex string
    
    echo "HMAC: " . $hmac_hex;
    ?>
    

    The code will produce output : HMAC: 857ab7a94a4c103e3a8cc0442db0d4745064bb73

    Live test : https://3v4l.org/q4rJj

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