Skip to Content

HMAC-SHA256 conversion in SAP PO and then conversion into Base 64

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);",


Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Jun 20, 2020 at 06:47 AM

    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




    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");
        	byte[] bytes = data.getBytes(java.nio.charset.StandardCharsets.UTF_8); 
        	String base64Encoded = java.util.Base64.getEncoder().encodeToString(sha256_HMAC.doFinal(bytes)); 
        	return base64Encoded;
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 15, 2020 at 12:28 PM

    Hi Kuldeep,

    No need to import any libraries. Please try using the code as is.



    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.