Hello Experts,
I have requirement to generate a Secure SHA-256 HMAC of string in CPI Groovy script.
like below sample
string: Account=788&Password=12345&Sender=Sender1ℜceiver=010456789&Text=Test1.
Secret key: FD92A200F4A9EBCB4896177CA2760DD
i have tried the below code but i don't know how to pass secret key and if there's a better solution.
Thank you!!
MessageDigest digest = MessageDigest.getInstance("SHA-256");
encodedhash = digest.digest(AhashingValue.getBytes(StandardCharsets.UTF_8));
hexString = new StringBuffer();
for (int i = 0; i < encodedhash.length; i++) {
String hex = Integer.toHexString(0xff & encodedhash[i]);
if(hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
def AuthTokenFinal = hexString.toString()
message.setHeader("ASHA-256","${AuthTokenFinal}")