i need to configurate payments in client application. In order to do that i need to generate signature (sha256) using private key. In payments documentation there is function in php to generate signature:
function createSignature($orderData, $serviceKey, $hashMethod)
{
$data = prepareData($orderData);
return hash($hashMethod, $data . $serviceKey);
}
So they use build in php function hash. Unfortunately we have application in java and i need to make same function in java, i have some string as input data and private key. I found solutions in java e.g:
public static String encode(String key, String data) throws Exception {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
sha256_HMAC.init(secret_key);
return Hex.encodeHexString(sha256_HMAC.doFinal(data.getBytes("UTF-8")));
}
But in php and in java i receive different hash. How to create same function in java as in php?