Calculate a hash in ABAP

In ABAP we can perform the following:

calculate_hash_for_raw

METHOD calculate_hash_for_raw.

    TRY.
        cl_abap_message_digest=>calculate_hash_for_raw(
          EXPORTING
            if_algorithm = 'SHA256'
            if_data      = iv_data
          IMPORTING
            ef_hashstring = ev_sha256
        ).
      CATCH cx_root.
        " Eh, what're you gonna do?
    ENDTRY.
  ENDMETHOD.

calculate_hash_for_string

METHOD calculate_hash_for_string.

    TRY.
        cl_abap_message_digest=>calculate_hash_for_char(
          EXPORTING
            if_algorithm = 'SHA256'
            if_data      = iv_data
          IMPORTING
            ef_hashstring = ev_sha256
        ).
      CATCH cx_root.
        " Eh, what're you gonna do?
    ENDTRY.
  ENDMETHOD.

 

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.