Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MD5 hash of a file in ABAP

Tags:

hash

md5

abap

I want to generate a MD5 hash of a text file in ABAP. I have not found any standard solution for generating it for a very big file. Function module CALCULATE_HASH_FOR_CHAR does not meet my requirements because it takes a string as an input parameter. Although it works for smaller files, in case of a for example 4 GB file one cannot construct such a big string.

Does anybody know whether there is a standard piece of coding for doing that (my google efforts did not bring me anything) or maybe someone has an MD5 algorithm in ABAP that calculates the hash of a file?

like image 962
Jagger Avatar asked Jan 17 '23 04:01

Jagger


2 Answers

It looks like the implementation of this algorithm is impossible in ABAP because of the fact that the language does not allow arithmetic overflows during the calculations. This should also answer the question why it has not been implemented so far in SAP system. Either way looks that there is no other way as to call an external tool which of course is, regrettably, hardly platform independent.

EDIT: Ok! So with a great help of René and the code of Fast MD5 Implementation in Java I created the implementation of MD5 algorithm in ABAP . This implementation allows to update the calculated hash with more bytes, which of course might be coming from different sources.

There is no method which takes a file so far but anyways most of the work has been done.

Some simple ABAP Unit tests are included in the code, which also document how to use it.

like image 55
Jagger Avatar answered Jan 21 '23 13:01

Jagger


Perhaps you could read the file in data blocks of a couple megabytes and create a hash list of those using the suggested function. And then create a single top hash using the generated hash list.

like image 27
René Avatar answered Jan 21 '23 15:01

René