Search code examples
pythonphphashhmac

PHP hash_hmac(sha512) to Python new hmac()


php code

    function get_signature($data, $secret_key) {
        $algo = "sha512";
        $result = hash_hmac(
            $algo,
            $data,
            $secret_key,
            false
        );

        return $result;
}

python code (Tried)

def get_signature(data, secret_key):
    signature = hmac.new(secret_key.encode(), data.encode(), hashlib.sha512).hexdigest()
    print(signature)

    return signature

the hashed value is not same. how can I get same value as in php code from python code?

thanks!


Solution

  • the code is working properly. the issue was on another code.