I am java developer and I am trying to use one WEB Service API (ticketutils) where they have explained two examples first one with PHP
and second one with C#
. Unfortunately I am not able to get any of them. I have mentioned PHP example below.
public function GenerateSignature($Secret,$PathAndQuery)
{
return base64_encode(\Zend_Crypt_Hmac::compute($Secret, 'sha256',
$PathAndQuery, \Zend_Crypt_Hmac::BINARY));
}
Can anyone please explain me how can I achieve the same with Java code? I have tried below code but it seems it's not generating proper outcome.
public static String generateSignature(String secrete, String pathAndQuery){
String encoded = null;
try {
MessageDigest md = MessageDigest.getInstance("SHA-256");
md.update(secrete.getBytes("UTF-8"));
md.update(pathAndQuery.getBytes("UTF-8"));
byte[] digest = md.digest();
encoded = Base64.getEncoder().encodeToString(digest);
} catch (Exception e) {
e.printStackTrace();
}
return encoded;
}
NOTE : I have used Java-8 for while writing above code.