Skip to content

Instantly share code, notes, and snippets.

@js1972
Created February 17, 2014 06:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save js1972/9045719 to your computer and use it in GitHub Desktop.
Save js1972/9045719 to your computer and use it in GitHub Desktop.
Calculate a HASH on a STRING #ABAP
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