Posted: Tue Oct 08, 2019 11:56 am Post subject: HmacSHA256.java Outo generating signature
Master
Joined: 05 Dec 2007 Posts: 296
Hi ,
I am connecting a service provider that requires the signature to be auto generated using HmacSHA256 and base64Encoded. My code seems to work fine , but some how the signature generated by my code is different to the signature generated by postman, with the exactly the same parameters sent.
Code:
public static String generateHashKey(final String secret, final String dataToSign) {
String hash = "";
try {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
sha256_HMAC.init(secret_key);
hash = Base64.encodeBase64String(sha256_HMAC.doFinal(dataToSign.getBytes()));
return hash;
}catch(Exception e ){};
return null;
and from my ESQL I am calling the java method
Code:
DECLARE content CHARACTER CAST (ASBITSTREAM(OutputRoot.JSON CCSID 1208) as CHARACTER CCSID 1208 );
DECLARE contentLength CHARACTER CAST (LENGTH(content)as CHARACTER);
DECLARE envdate CHARACTER cast(CURRENT_TIMESTAMP as CHARACTER FORMAT 'EEE,dd MMM YYYY HH:mm:ss')|| ' GMT' ;
DECLARE dataToSign CHARACTER '(request-target): post ' ||gatewayURL ||'searchCustomer ||'\n'||
'host: ' || g ||'\n'||
'date: ' ||envdate ||'\n'||
'content-type: ' || 'application/json' ||'\n'||
'content-length: ' ||contentLength ;
CALL hmacSha256Auth(apisecret,dataToSign) INTO signature;
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum