This function attempts to calculate a MD5 checksum of a file. It is returned as a 32 character string - lower case hexadecimal.
This file is a one-file implementation. The code is concise and can also be included in your own functions. The purpose of this is to avoid having to compile c-code into mex files for simple implementations.
MD5 checksums should be used only to check for the file integrity. They are cryptographically broken, and unsuitable for security purposes.
Marcin Konowalczyk (2019). JavaMD5 (https://www.mathworks.com/matlabcentral/fileexchange/55746-javamd5), MATLAB Central File Exchange. Retrieved .
For a 200MB this takes over 6 seconds on my Win7/64, Core2Duo, Matlab 2015b. GetMD5.mex meeds only 0.9 seconds. Although the C implementation is known to be faster, the factor 6.6 is not expected.
If I replace the code for importing the data: "fread(fid)" by "fread(fid, inf, '*uint8')", JavaMD5 needs 2.2 seconds only. Importing the file as DOUBLE uses 8 times as much memory as using UINT8 directly. For a file with several GB this would help to avoid exhausting the RAM completely.
DataHash calls the Java method also, but requires 1.5 seconds only, because the file is processed in chunks of 1MB.
If a file is not existing, a regular ERROR would be better than replying an invalid hash. Note that FOPEN is smart and searchs the Matlab PATH automatically. So better use absolute file names as input.
added error IDs
Replaced "fread(fid)" by "fread(fid, inf, '*uint8') for speed