OOP API SHA1 and SHA2 implementations. See std.digest for differences between template and OOP API.
These are convenience aliases for std.digest.digest using the SHA implementation.
Template API SHA1/SHA2 implementation. Supports: SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.
//Template API import std.digest.sha; ubyte[20] hash1 = sha1Of("abc"); assert(toHexString(hash1) == "A9993E364706816ABA3E25717850C26C9CD0D89D"); ubyte[28] hash224 = sha224Of("abc"); assert(toHexString(hash224) == "23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7"); //Feeding data ubyte[1024] data; SHA1 sha1; sha1.start(); sha1.put(data[]); sha1.start(); //Start again sha1.put(data[]); hash1 = sha1.finish();
//OOP API import std.digest.sha; auto sha1 = new SHA1Digest(); ubyte[] hash1 = sha1.digest("abc"); assert(toHexString(hash1) == "A9993E364706816ABA3E25717850C26C9CD0D89D"); auto sha224 = new SHA224Digest(); ubyte[] hash224 = sha224.digest("abc"); assert(toHexString(hash224) == "23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7"); //Feeding data ubyte[1024] data; sha1.put(data[]); sha1.reset(); //Start again sha1.put(data[]); hash1 = sha1.finish();
CTFE: Digests do not work in CTFE
Computes SHA1 and SHA2 hashes of arbitrary data. SHA hashes are 20 to 64 byte quantities (depending on the SHA algorithm) that are like a checksum or CRC, but are more robust.
SHA2 comes in several different versions, all supported by this module: SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224 and SHA-512/256.
This module conforms to the APIs defined in std.digest. To understand the differences between the template and the OOP API, see std.digest.
This module publicly imports std.digest and can be used as a stand-alone module.