cancel
Showing results for 
Search instead for 
Did you mean: 

Python code for fingerprint generation

 

Using PHP  for a transaction posted to the SIM gateway, fingerprint generation is based on the following function:

 

function hmac ($key, $data)
{
return (bin2hex (mhash(MHASH_MD5, $data, $key)));
}

Not being very familiar with either PHP or hash functions, I'm hoping someone can tell me what the equivalent Python code is to generate a valid fingerprint (presumably using the hashlib module).

 

 

gpetty
Member
1 ACCEPTED SOLUTION

Accepted Solutions

The code posted previously needs to be corrected to reverse the order of the arguments to hmac.new().  The following is what I'm now using successfully in my Python-based interface to the gateway:

 

 

import hmac
def HMAC(key,data):
    return(hmac.new(key,data).hexdigest())

View solution in original post

2 REPLIES 2

 

After considerable trial and error, I find that the following appears to produce the same output as the PHP version:

 

import hmac
def HMAC(key,data):
    return(hmac.new(data,key).hexdigest())

gpetty
Member

The code posted previously needs to be corrected to reverse the order of the arguments to hmac.new().  The following is what I'm now using successfully in my Python-based interface to the gateway:

 

 

import hmac
def HMAC(key,data):
    return(hmac.new(key,data).hexdigest())