[ABAP] MD5, SHA1, SHA256, SHA384, SHA512 HASH-Summen berechnen

Variante 1 (Strings)

* MD5, SHA1, SHA256, SHA384, SHA512
DATA(lv_algo) = |MD5|.
* zu kodierende String-Daten
DATA(lv_data) = |Teststring|.

* Hash-Wert als Hex-Encoded String
DATA: lv_hashstring TYPE string.
* Hash-Wert binär als XString
DATA: lv_hashxstring TYPE xstring.
* Hash-Wert als Base64-Encoded String
DATA: lv_hashb64string TYPE string.

TRY.
* Generische Hash-Funktion (Char-Input)
    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 ).
    cl_demo_output=>write_data( lv_algo ).
    cl_demo_output=>write_data( lv_data ).
    cl_demo_output=>write_data( lv_hashstring ).
    cl_demo_output=>write_data( lv_hashxstring ).
    cl_demo_output=>write_data( lv_hashb64string ).
    cl_demo_output=>display( ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

Variante 2 (Bytefolgen / RAW)

* MD5, SHA1, SHA256, SHA384, SHA512
DATA(lv_algo) = |MD5|.
* zu kodierende String-Daten
DATA(lv_data) = |Teststring|.
* zu kodierende String-Daten als XSTRING
DATA(lv_datax) = cl_abap_message_digest=>string_to_xstring( lv_data ).

* Hash-Wert als Hex-Encoded String
DATA: lv_hashstring TYPE string.
* Hash-Wert binär als XString
DATA: lv_hashxstring TYPE xstring.
* Hash-Wert als Base64-Encoded String
DATA: lv_hashb64string TYPE string.

TRY.
* Generische Hash-Funktion (XString)
    cl_abap_message_digest=>calculate_hash_for_raw( EXPORTING
                                                      if_algorithm     = lv_algo
                                                      if_data          = lv_datax
                                                    IMPORTING
                                                      ef_hashstring    = lv_hashstring
                                                      ef_hashxstring   = lv_hashxstring
                                                      ef_hashb64string = lv_hashb64string ).
    cl_demo_output=>write_data( lv_algo ).
    cl_demo_output=>write_data( lv_data ).
    cl_demo_output=>write_data( lv_datax ).
    cl_demo_output=>write_data( lv_hashstring ).
    cl_demo_output=>write_data( lv_hashxstring ).
    cl_demo_output=>write_data( lv_hashb64string ).
    cl_demo_output=>display( ).
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.