Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

HMAC SHA256 result SAP vs Java

former_member283466
Discoverer
0 Kudos

Hello

I'm getting different HMAC code for the same input data and secret key comparing CL_ABAP_HMAC=>CALCULATE_HMAC_FOR_CHAR (using SHA256 algorithm) with result of javax.crypto.Mac (using HmacSHA256 algorithm).

Does anyone knows, if algorithms used by those classes are exactly the same. I would suspect that it should be that way, but as I'm getting different hash code in result for the same input I started to doubt. Or maybe I'm doing something wrong?

Thanks for any help

Regards,

Slawek

1 ACCEPTED SOLUTION

martin_voros
Active Contributor

Hi,

ABAP version seems to be working fine. Maybe you are just mixing types and it does not matter. E.g. on this site

Free Online HMAC Generator / Checker Tool (MD5, SHA-1, SHA-256, etc.) - FreeFormatter.com

you can calculate HMAC-256. I did it for key = "ABC" and data = "ABC". The result is 87bed3bb8821d3196854b37290e5a1c3e518f99eff4101219d1d492fed1eba1a. To get the same value you have to first convert ABC to xstring using method STRING_TO_XSTRING. This gives you 414243. Then if you just set key to 414243 and data to ABC then the returned MAC from CALCULATE_HMAC_FOR_CHAR is same as the one above. I did this all in SE24 just by testing the class.

Cheers

2 REPLIES 2

martin_voros
Active Contributor

Hi,

ABAP version seems to be working fine. Maybe you are just mixing types and it does not matter. E.g. on this site

Free Online HMAC Generator / Checker Tool (MD5, SHA-1, SHA-256, etc.) - FreeFormatter.com

you can calculate HMAC-256. I did it for key = "ABC" and data = "ABC". The result is 87bed3bb8821d3196854b37290e5a1c3e518f99eff4101219d1d492fed1eba1a. To get the same value you have to first convert ABC to xstring using method STRING_TO_XSTRING. This gives you 414243. Then if you just set key to 414243 and data to ABC then the returned MAC from CALCULATE_HMAC_FOR_CHAR is same as the one above. I did this all in SE24 just by testing the class.

Cheers

0 Kudos

This was of great help !