You need to sign in to do that
Don't have an account?
usersfdc21
How to create a HmacSHA256 hash in Salesforce to match external service
Hi guys,
I have created Rest API to integrate Salesforce with banking system.
I am facing problem with HmacSha256 encryption. I am using as below:
Blob blobSign = Crypto.generateMac('Hmac-SHA256', Blob.valueOf(privKey + xmlOutput.length() + unixTime));
String HMACKey = EncodingUtil.base64Encode(blobSign);
I am getting error 403.
Any one know how to connect external system.
Thanks in advance.
I have created Rest API to integrate Salesforce with banking system.
I am facing problem with HmacSha256 encryption. I am using as below:
Blob blobSign = Crypto.generateMac('Hmac-SHA256', Blob.valueOf(privKey + xmlOutput.length() + unixTime));
String HMACKey = EncodingUtil.base64Encode(blobSign);
I am getting error 403.
Any one know how to connect external system.
Thanks in advance.
Please use the below code for your problem.
Thanks
Gyani
http://www.mirketa.com
Thank you very much for replying me.
I tried it but unable to connect to external system. can I have your email Id ?
I am still facing 403 error for the below code:
DateTime dateTimeNow = dateTime.now();
String unixTime = ''+dateTimeNow.getTime()/1000;
String data = '<LoanApplication><LoanId>10</LoanId><LoanReference>APP123456</LoanReference></LoanApplication>';
String privKey = 'privkeyabc';
String publicKey = 'publickeyabc';
String responseBody;
blob blobSign = Crypto.generateDigest('SHA256', Blob.valueOf(privKey + data + unixTime));
String HMACKey = EncodingUtil.base64Encode(blobSign);
String endpoint='https://api-test.abc.com.au/abc/new/';
HttpRequest request = new HttpRequest();
request.setMethod('POST');
request.setEndpoint(endpoint);
request.setHeader('Content-Type', 'application/xml');
request.setHeader('API-KEY',publicKey);
request.setHeader('API-HMAC',HMACKey );
request.setHeader('API-Timestamp',unixTime);
request.setBody(data);
System.debug('@@@XML Output'+data);
Http http = new Http();
HttpResponse response = http.send(request);
responseBody = response.getBody();
System.debug('@@@Response:'+ Response);
System.debug('@@@Response Body:'+ ResponseBody);
System.debug('@@@time: '+unixTime);
System.debug('@@@HMACKey: '+ HMACKey);
System.debug('@@@BlobSign: ' + blobSign);
System.debug('@@@Data Length: ' + data.Length());
I have same probelm. can you please share code to create hmacSHA256?
Thanks in Advance.