ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum IndexWebSphere Message Broker SupportHmacSHA256.java Outo generating signature

Post new topicReply to topic
HmacSHA256.java Outo generating signature View previous topic :: View next topic
Author Message
matuwe
PostPosted: Tue Oct 08, 2019 11:56 am Post subject: HmacSHA256.java Outo generating signature Reply with quote

Master

Joined: 05 Dec 2007
Posts: 283

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;


Has anyone done this before
Back to top
View user's profile Send private message
Display posts from previous:
Post new topicReply to topic Page 1 of 1

MQSeries.net Forum IndexWebSphere Message Broker SupportHmacSHA256.java Outo generating signature
Jump to:



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
Protected by Anti-Spam ACP


Theme by Dustin Baccetti
Powered by phpBB 2001, 2002 phpBB Group

Copyright MQSeries.net. All rights reserved.