Turning a python function into a function in PHP

0

Would anyone know how to turn this python function into a function in php?

def createSignature(clientId, apiKey, privateKey, nonce):
    message = str(nonce) + str(clientId) + apiKey 
    signature = hmac.new(privateKey, message, digestmod=hashlib.sha256).hexdigest()

Thank you!

    
asked by anonymous 16.12.2017 / 17:21

1 answer

2

Well, the code is not indented, so I suppose it is:

def createSignature(clientId, apiKey, privateKey, nonce): 
 message = str(nonce) + str(clientId) + apiKey 
 signature = hmac.new(privateKey, message, digestmod=hashlib.sha256).hexdigest()

That would be exactly:

function createSignature($id, $pk, $sk, $nonce){
     $message = $nonce . $id . $pk; 
     $signature = hash_hmac('sha256', $message, $sk, false);
}

hash_hmac already has the result in hexadecimal, there is no reason to convert it , so there is no equivalent of .hexdigest() being used. Of course you should add some return (or some other method to get the information processed), but that is not present in the given code.

    
16.12.2017 / 17:53