2022 Dec 30 8:34 PM
Hi ALL,
I have a request from my company to create a hash value of the normalized text using SHA256 and then convert the hash value from an array of 32 bytes to a hexadecimal string of 64 characters and last use the hexadecimal as a string
here is my code :
DATA(lv_algo) = |SHA256|.
DATA(lv_data) = lv_boy2. "|lv_boy2|.
DATA: lv_hashstring TYPE string.
DATA: lv_hashxstring TYPE xstring.
DATA: lv_hashb64string TYPE string.
cl_abap_message_digest=>calculate_hash_for_char( EXPORTING
if_algorithm = lv_algo
if_data = lv_data
IMPORTING
ef_hashstring = lv_hashstring
ef_hashxstring = lv_hashxstring
ef_hashb64string = lv_hashb64string ).
then I use lv_hashstring and convert it to hex 64 characters
I am asking if that code is correct because I think I miss something
2022 Dec 31 9:07 AM
Difficult to know that "something" you "think is missing".
The hash code you obtain is not "an array of 32 bytes", it's simply "32 bytes".
Instead of "a hexadecimal string of 64 characters", I'd say a "string of 64 hexadecimal characters".
In the code you show, you are using base64, which is something not related to your question.
To "convert from 32 bytes to a string of 64 hexadecimal characters", that's possible using the implicit conversion in ABAP from type X or XSTRING to C or STRING:
lv_hashstring = lv_hashxstring.
But of course, you can get this same hash code as "a string of 64 hexadecimal characters" directly from the parameter EF_HASHSTRING of the hash method.