View source code
Display the source code in std/digest/sha.d from which this page was generated on github.
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 using local clone.

Alias std.digest.sha.SHA256Digest

OOP API SHA1 and SHA2 implementations. See std.digest for differences between template and OOP API.

alias SHA256Digest = std.digest.WrapperDigest!(std.digest.sha.SHA!(512,256).SHA);

This is an alias for std.digest.WrapperDigest!SHA1, see there for more information.

Example

//Simple example, hashing a string using Digest.digest helper function
auto sha = new SHA1Digest();
ubyte[] hash = sha.digest("abc");
//Let's get a hash string
writeln(toHexString(hash)); // "A9993E364706816ABA3E25717850C26C9CD0D89D"

//The same, but using SHA-224
auto sha224 = new SHA224Digest();
ubyte[] hash224 = sha224.digest("abc");
//Let's get a hash string
writeln(toHexString(hash224)); // "23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7"

Example

//Let's use the OOP features:
void test(Digest dig)
{
  dig.put(cast(ubyte) 0);
}
auto sha = new SHA1Digest();
test(sha);

//Let's use a custom buffer:
ubyte[20] buf;
ubyte[] result = sha.finish(buf[]);
writeln(toHexString(result)); // "5BA93C9DB0CFF93F52B521D7420E43F6EDA2784F"

Authors

The routines and algorithms are derived from the Secure Hash Signature Standard (SHS) (FIPS PUB 180-2).
Kai Nacke, Johannes Pfau, Nick Sabalausky

License

Boost License 1.0.