Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
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 usinga local clone.

std.digest.md

Computes MD5 hashes of arbitrary data. MD5 hashes are 16 byte quantities that are like a checksum or CRC, but are more robust.
CategoryFunctions
Template APIMD5 
OOP APIMD5Digest 
Helpersmd5Of 
This module conforms to the APIs defined instd.digest. To understand the differences between the template and the OOP API, seestd.digest.
This module publicly importsstd.digest and can be used as a stand-alone module.
License:
Boost License 1.0.

CTFEDigests do not work in CTFE

Authors:
Piotr Szturmaj, Kai Nacke, Johannes Pfau
The routines and algorithms are derived from theRSA Data Security, Inc. MD5 Message-Digest Algorithm.

ReferencesWikipedia on MD5

Sourcestd/digest/md.d

Examples:
//Template APIimport std.digest.md;//Feeding dataubyte[1024] data;MD5 md5;md5.start();md5.put(data[]);md5.start();//Start againmd5.put(data[]);auto hash = md5.finish();
Examples:
//OOP APIimport std.digest.md;auto md5 =new MD5Digest();ubyte[] hash = md5.digest("abc");writeln(toHexString(hash));// "900150983CD24FB0D6963F7D28E17F72"//Feeding dataubyte[1024] data;md5.put(data[]);md5.reset();//Start againmd5.put(data[]);hash = md5.finish();
structMD5;
Template API MD5 implementation. Seestd.digest for differences between template and OOP API.
Examples:
//Simple example, hashing a string using md5Of helper functionubyte[16] hash = md5Of("abc");//Let's get a hash stringwriteln(toHexString(hash));// "900150983CD24FB0D6963F7D28E17F72"
Examples:
//Using the basic APIMD5 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);writeln(toHexString(md5.finish()));// "93B885ADFE0DA089CDF634904FD59F71"
pure nothrow @nogc @trusted voidput(scope const(ubyte)[]data...);
Use this to feed the digest with data. Also implements thestd.range.primitives.isOutputRange interface forubyte andconst(ubyte)[].

Example

MD5 dig;dig.put(cast(ubyte) 0);//single ubytedig.put(cast(ubyte) 0,cast(ubyte) 0);//variadicubyte[10] buf;dig.put(buf);//buffer

pure nothrow @nogc @safe voidstart();
Used to (re)initialize the MD5 digest.

NoteFor this MD5 Digest implementation calling start after default construction is not necessary. Calling start is only necessary to reset the Digest.

Generic code which deals with different Digest types should always call start though.

Example

MD5 digest;//digest.start(); //Not necessarydigest.put(0);

pure nothrow @nogc @trusted ubyte[16]finish();
Returns the finished MD5 hash. This also callsstart to reset the internal state.
Examples:
//Simple exampleMD5 hash;hash.start();hash.put(cast(ubyte) 0);ubyte[16] result = hash.finish();
automd5Of(T...)(Tdata);
This is a convenience alias forstd.digest.digest using the MD5 implementation.
Examples:
ubyte[16] hash =md5Of("abc");writeln(hash);// digest!MD5("abc")
aliasMD5Digest = std.digest.WrapperDigest!(MD5).WrapperDigest;
OOP API MD5 implementation. Seestd.digest for differences between template and OOP API.
This is an alias forstd.digest.WrapperDigest!MD5, see there for more information.
Examples:
//Simple example, hashing a string using Digest.digest helper functionauto md5 =newMD5Digest();ubyte[] hash = md5.digest("abc");//Let's get a hash stringwriteln(toHexString(hash));// "900150983CD24FB0D6963F7D28E17F72"
Examples:
//Let's use the OOP features:void test(Digest dig){ dig.put(cast(ubyte) 0);}auto md5 =newMD5Digest();test(md5);//Let's use a custom buffer:ubyte[16] buf;ubyte[] result = md5.finish(buf[]);writeln(toHexString(result));// "93B885ADFE0DA089CDF634904FD59F71"
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 04:08:21 2026

[8]ページ先頭

©2009-2026 Movatter.jp