Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
std.digest.md
Category | Functions |
---|---|
Template API | MD5 |
OOP API | MD5Digest |
Helpers | md5Of |
Boost License 1.0 CTFE:
Digests do not work in CTFE Authors:
Piotr Szturmaj, Kai Nacke, Johannes Pfau
The routines and algorithms are derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm. References:
Wikipedia on MD5 Source:
std/digest/md.d
- struct MD5;
- Template API MD5 implementation.
See std.digest.digest for differences between template and OOP API.
Examples:
//Simple example, hashing a string using md5Of helper function ubyte[16] hash = md5Of("abc"); //Let's get a hash string assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
Examples://Using the basic API MD5 hash; hash.start(); ubyte[1024] data; //Initialize data here... hash.put(data); ubyte[16] result = hash.finish();
Examples://Let's use the template features: void doSomething(T)(ref T hash) if(isDigest!T) { hash.put(cast(ubyte)0); } MD5 md5; md5.start(); doSomething(md5); assert(toHexString(md5.finish()) == "93B885ADFE0DA089CDF634904FD59F71");
- auto md5Of(T...)(T data);
- This is a convenience alias for std.digest.digest.digest using the
MD5 implementation.
Examples:
ubyte[16] hash = md5Of("abc"); assert(hash == digest!MD5("abc"));
- alias MD5Digest = std.digest.digest.WrapperDigest!(MD5).WrapperDigest;
- OOP API MD5 implementation.
See std.digest.digest for differences between template and OOP API.
This is an alias for std.digest.digest.WrapperDigest!MD5, see
std.digest.digest.WrapperDigest for more information.
Examples:
//Simple example, hashing a string using Digest.digest helper function auto md5 = new MD5Digest(); ubyte[] hash = md5.digest("abc"); //Let's get a hash string assert(toHexString(hash) == "900150983CD24FB0D6963F7D28E17F72");
Examples://Let's use the OOP features: void test(Digest dig) { dig.put(cast(ubyte)0); } auto md5 = new MD5Digest(); test(md5); //Let's use a custom buffer: ubyte[16] buf; ubyte[] result = md5.finish(buf[]); assert(toHexString(result) == "93B885ADFE0DA089CDF634904FD59F71");