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.ripemd

Computes RIPEMD-160 hashes of arbitrary data. RIPEMD-160 hashes are 20 byte quantities that are like a checksum or CRC, but are more robust.
CategoryFunctions
Template APIRIPEMD160 
OOP APIRIPEMD160Digest 
Helpersripemd160Of 
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:
Kai Nacke
The algorithm was designed by Hans Dobbertin, Antoon Bosselaers, and Bart Preneel.
The D implementation is a direct translation of the ANSI C implementation by Antoon Bosselaers.

References

Sourcestd/digest/ripemd.d

Examples:
//Template APIimport std.digest.md;ubyte[20] hash = ripemd160Of("abc");writeln(toHexString(hash));// "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC"//Feeding dataubyte[1024] data;RIPEMD160 md;md.start();md.put(data[]);md.start();//Start againmd.put(data[]);hash = md.finish();
Examples:
//OOP APIimport std.digest.md;auto md =new RIPEMD160Digest();ubyte[] hash = md.digest("abc");writeln(toHexString(hash));// "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC"//Feeding dataubyte[1024] data;md.put(data[]);md.reset();//Start againmd.put(data[]);hash = md.finish();
structRIPEMD160;
Template API RIPEMD160 implementation. Seestd.digest for differences between template and OOP API.
Examples:
//Simple example, hashing a string using ripemd160Of helper functionubyte[20] hash = ripemd160Of("abc");//Let's get a hash stringwriteln(toHexString(hash));// "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC"
Examples:
//Using the basic APIRIPEMD160 hash;hash.start();ubyte[1024] data;//Initialize data here...hash.put(data);ubyte[20] result = hash.finish();
Examples:
//Let's use the template features:void doSomething(T)(ref T hash)if (isDigest!T){    hash.put(cast(ubyte) 0);}RIPEMD160 md;md.start();doSomething(md);writeln(toHexString(md.finish()));// "C81B94933420221A7AC004A90242D8B1D3E5070D"
Examples:
//Simple exampleRIPEMD160 hash;hash.start();hash.put(cast(ubyte) 0);ubyte[20] result = hash.finish();writeln(toHexString(result));// "C81B94933420221A7AC004A90242D8B1D3E5070D"
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

RIPEMD160 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 RIPEMD160 digest.

NoteFor this RIPEMD160 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

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

pure nothrow @nogc @trusted ubyte[20]finish();
Returns the finished RIPEMD160 hash. This also callsstart to reset the internal state.

Example

//Simple exampleRIPEMD160 hash;hash.start();hash.put(cast(ubyte) 0);ubyte[20] result = hash.finish();assert(toHexString(result) =="C81B94933420221A7AC004A90242D8B1D3E5070D");

autoripemd160Of(T...)(Tdata);
This is a convenience alias forstd.digest.digest using the RIPEMD160 implementation.
Examples:
ubyte[20] hash =ripemd160Of("abc");writeln(hash);// digest!RIPEMD160("abc")
aliasRIPEMD160Digest = std.digest.WrapperDigest!(RIPEMD160).WrapperDigest;
OOP API RIPEMD160 implementation. Seestd.digest for differences between template and OOP API.
This is an alias forstd.digest.WrapperDigest!RIPEMD160, see there for more information.
Examples:
//Simple example, hashing a string using Digest.digest helper functionauto md =newRIPEMD160Digest();ubyte[] hash = md.digest("abc");//Let's get a hash stringwriteln(toHexString(hash));// "8EB208F7E05D987A9B044A8E98C6B087F15A0BFC"
Examples:
//Let's use the OOP features:void test(Digest dig){  dig.put(cast(ubyte) 0);}auto md =newRIPEMD160Digest();test(md);//Let's use a custom buffer:ubyte[20] buf;ubyte[] result = md.finish(buf[]);writeln(toHexString(result));// "C81B94933420221A7AC004A90242D8B1D3E5070D"
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Sat Feb 21 04:08:22 2026

[8]ページ先頭

©2009-2026 Movatter.jp