Computes MD5 digests of arbitrary data. MD5 digests are 16 byte quantities that are like a checksum or crc, but are more robust.
There are two ways to do this. The first does it all in one function call to sum(). The second is for when the data is buffered.
- Bugs:
- MD5 digests have been demonstrated to not be unique.
- Author:
- The routines and algorithms are derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm.
- References:
- Wikipedia on MD5
- Example:
import std.md5;
private import std.stdio;
private import std.string;
private import std.c.stdio;
private import std.c.string;
int main(char[][] args) {
foreach(char[] arg; args)
MDFile(arg);
return 0;
}
void MDFile(char[] filename) {
FILE* file;
MD5_CTX context;
int len;
ubyte[4 * 1024] buffer;
ubyte digest[16];
if((file = fopen(std.string.toStringz(filename), "rb")) == null)
writefln("%s can't be opened", filename);
else {
context.start();
while((len = fread(buffer, 1, buffer.sizeof, file)) != 0)
context.update(buffer[0 .. len]);
context.finish(digest);
fclose(file);
writefln("MD5 (%s) = %s", filename, digestToString(digest));
}
}