Is there an equivalent of PHP's hash_hmac in Python/Django?

Question:

I want to forward my visitors to a 3rd party paysite. This 3rd party will process their payment and POST to me a 64 character token generated from a unique order number and shared password using PHP’s hash_hmac using the sha256 algorithm, like so:

$token = hash_hmac("sha256", "12345", "sharedpassword");

Then I want to use the same algorithm on my end to generate the (hopefully) the same token to verify the user has paid. The problem is I cannot find an equivalent function or way to replicate the function in Python. The closest I’ve come is Python’s hashlib, but there doesn’t appear to be a function that can take in 2 arguments – the data and the shared password. Does anyone know of an equivalent of hash_hmac that would be applicable in this case?

Asked By: kshen

||

Answers:

You want hmac.

hmac.new("sharedpassword", "12345", hashlib.sha256).hexdigest()
Answered By: Amber
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.