Skip to Content
0

UTF-8 Encoding and Hash256 with salt as secrete

Aug 29, 2017 at 09:55 AM

88

avatar image

Hi everyone,

My requirement is to generate an hash string to be sent in the Webservice request.

I have the username and password. I have to encode these with UTF-8 format and Hash them with password as salt.

The lv_username is built by concatenating the timestamp, guid and username.

TRY.
CALL METHOD cl_abap_message_digest=>calculate_hash_for_char
EXPORTING
if_algorithm = 'SHA256'
if_data = lv_username
IMPORTING
ef_hashb64string = lv_hash_b64string.
ENDTRY.

I am able to generate hashed 64bit string. However, how can i use the password as salt while hashing it?

Also, I have to encode the password in UTF-8 format before using it as salt. I have used the 'Convert' method in class 'cl_abap_conv_out_ce'. Since, Password is a string with combination of integers and characters I am not not able to encode it. how can I encode it to UTF-8?

Thank you in advance.

Regards,

Kethan.

10 |10000 characters needed characters left characters exceeded

Are you trying to calculate a "PasswordDigest" ? (for instance, WSSE) If so, why don't you use the built-in function in SOAMANAGER, or is there any reason why you can't use it ?

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
KETHAN UPPALAPATI Nov 09, 2017 at 06:53 AM
0

Hi,

We can use the calculate_hmac_for_char of cl_abap_hmac class to hash the string with salt. In the below code, If_key parameter is used to pass the salt.

TRY.
CALL METHOD cl_abap_hmac=>calculate_hmac_for_char
EXPORTING
if_algorithm = 'SHA256 '
if_key = lv_api_secret" Salt
if_data = lv_apikey
IMPORTING
ef_hmacb64string = lv_api_hashb64string.
CATCH cx_abap_message_digest .
ENDTRY.

Share
10 |10000 characters needed characters left characters exceeded