use cl_abap_hmac for calculating md5 (#4355)

This commit is contained in:
Lars Hvam 2020-12-25 10:10:43 +01:00 committed by GitHub
parent e1e039a446
commit 7a2ac816c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,7 @@ CLASS zcl_abapgit_http_digest DEFINITION
RAISING
zcx_abapgit_exception.
PROTECTED SECTION.
PRIVATE SECTION.
DATA: mv_ha1 TYPE string,
mv_username TYPE string,
@ -83,26 +84,23 @@ CLASS ZCL_ABAPGIT_HTTP_DIGEST IMPLEMENTATION.
METHOD md5.
DATA: lv_xstr TYPE xstring,
lv_hash TYPE xstring.
DATA lv_xstr TYPE xstring.
DATA lv_hash TYPE xstring.
DATA lv_empty TYPE xstring.
lv_xstr = zcl_abapgit_convert=>string_to_xstring_utf8( iv_data ).
CALL FUNCTION 'CALCULATE_HASH_FOR_RAW'
EXPORTING
alg = 'MD5'
data = lv_xstr
IMPORTING
hashxstring = lv_hash
EXCEPTIONS
unknown_alg = 1
param_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
zcx_abapgit_exception=>raise( 'error from CALCULATE_HASH_FOR_RAW' ).
ENDIF.
TRY.
cl_abap_hmac=>calculate_hmac_for_raw(
EXPORTING
if_algorithm = 'MD5'
if_key = lv_empty
if_data = lv_xstr
IMPORTING
ef_hmacxstring = lv_hash ).
CATCH cx_abap_message_digest.
zcx_abapgit_exception=>raise( 'error calculating md5' ).
ENDTRY.
rv_hash = lv_hash.
TRANSLATE rv_hash TO LOWER CASE.