image thumbnail

GetMD5

version 2.1.1 (23.5 KB) by Jan
Get MD5 of files or arrays as fast C-Mex

7.1K Downloads

Updated 07 Mar 2019

View License

MD5 hash of files, strings and arrays (RFC 1321)
Hash = GetMD5(Data, Mode, Format)
INPUT:
Data: File name or array.
Mode: CHAR to declare the type of the 1st input.
'File': Data is a file name as CHAR.
'8Bit': If Data is a CHAR array, only the 8 bit ASCII part is used.
'Binary': The MD5 sum is obtained for the contents of Data.
This works for numerical, CHAR and LOGICAL arrays.
'Array': Include the class and dimensions of Data in the MD5
sum. This can be applied for (nested) structs, cells
and sparse arrays also.
Format: CHAR, format of the output: hex, HEX, double, uint8, base64

OUTPUT:
Hash: A 128 bit number is replied in the specified format.

This function is at least 2 times faster than the corresponding Java method.
For shorter arrays this C-Mex implementation is much faster, see the output
of the included unit test function.
The function DataHash can reply SHA hashes also, but it is remarkably
slower due to the overhead of calling Java. For nested structs this C-Mex
can be 100 times faster. See:
http://www.mathworks.com/matlabcentral/fileexchange/31272-datahash
The C-function must be compiled before using: Call the M-function without
inputs. If you do not have a C-compiler, pre-compiled files can be
downloaded: http://n-simon.de/mex

Cite As

Jan (2021). GetMD5 (https://www.mathworks.com/matlabcentral/fileexchange/25921-getmd5), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2018b
Compatible with R13SP1 and later releases
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired by: MD5 in MATLAB

Inspired: bimac/md5sum, JavaMD5, DataHash

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!