Created
February 17, 2014 06:32
-
-
Save js1972/9045719 to your computer and use it in GitHub Desktop.
Calculate a HASH on a STRING #ABAP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
method calculate_hash. | |
" importing: string_data TYPE STRING | |
" returning: hash_value TYPE STRING | |
" | |
" Calculate the hash value for a given string and return as Base64. | |
" | |
data: lo_digest type ref to cl_abap_message_digest, | |
converter type ref to cl_abap_conv_out_ce, | |
data_as_xstring type xstring. | |
try. | |
lo_digest = cl_abap_message_digest=>get_instance( 'sha1' ). | |
"update digest with input | |
converter = cl_abap_conv_out_ce=>create( ). | |
converter->convert( | |
exporting | |
data = string_data | |
importing | |
buffer = data_as_xstring | |
). | |
lo_digest->update( if_data = data_as_xstring ). | |
"finalise digest | |
lo_digest->digest( ). | |
hash_value = lo_digest->to_base64( ). | |
catch cx_abap_message_digest. | |
clear hash_value. | |
catch cx_sy_codepage_converter_init | |
cx_sy_conversion_codepage | |
cx_parameter_invalid_type. | |
clear hash_value. | |
endtry. | |
endmethod. "calculate_hash |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment