on 06-20-2020 6:35 AM
Dear Experts,
Need help on converting an storage key into - HMAC-SHA 256 and then convert it into Base #64 in SAP PO .
I have postman project - which is doing this in JSON , i need it's equivalent way to do in SAP PO.
Below is the piece of code from Postman Project -
"// Hash it using HMAC-SHA256 and then encode using base64", "const storageKey = pm.variables.get(\"azure_storage_key\");", "const signatureBytes = crypto.HmacSHA256(signatureRaw, crypto.enc.Base64.parse(storageKey));", "const signatureEncoded = signatureBytes.toString(crypto.enc.Base64);",
Thanks
Hi kdbhardwaj15,
No need to import any libraries. Please try using the code as is.
Regards
Anupam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kuldeep,
Please try using following code to get the required result
so for these input key="1234" and data="hello world" I get following output
XOD+lv5JiwIfA5+KvNqMJvfzsP29ZsngUQVo33EUv+w=
Regards
Anupam
static String Base64Encoding (String key,String data) throws Exception
{
javax.crypto.Mac sha256_HMAC = javax.crypto.Mac.getInstance("HmacSHA256");
javax.crypto.spec.SecretKeySpec secret_key = new javax.crypto.spec.SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] bytes = data.getBytes(java.nio.charset.StandardCharsets.UTF_8);
String base64Encoded = java.util.Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(bytes));
return base64Encoded;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Anupam,
What are the libraries i need to import to make this code working?
Thanks
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.