Import std.crypto.hashes
std.crypto.hashes
The MD5, SHA-1, SHA-256, and SHA-512 hashes.
Md5, Sha1, Sha256, and Sha512, over mbedTLS: each one's Hash gives the hash of bytes, or of a String's bytes, at once, and an object of it adds them in turn. MD5 and SHA-1 are broken, since two inputs with one hash can be made, so they're only for checksums and the formats that ask for them; Sha256 and Sha512 are for the rest.
std/crypto/hashes.fb
Types
Hasher
interface
Public Interface Hasher
What hashes bytes added to it in turn. Finish gives the hash of what was added, and starts again, empty.
Examples
Function HashOf(hasher: Hasher, parts: String[]): UInt8[]
For part In parts
hasher.Add(part)
End For
Return hasher.Finish()
End Function
Expect(HashOf(Sha256(), ["a", "b", "c"]) == Sha256.Hash("abc"))-
Adds
datato what it hashes. -
Adds
text's UTF-8 bytes to what it hashes. -
The hash of what was added, which starts it again, empty.
Md5
class
Public Class Md5 Implements Hasher
MD5's 16 bytes, only for checksums.
Examples
Expect(Hex.Encode(Md5.Hash("")) == "d41d8cd98f00b204e9800998ecf8427e")-
A new Md5, of nothing.
-
The MD5 of
data. -
The MD5 of
text's UTF-8 bytes. -
Adds
datato what it hashes. -
Adds
text's UTF-8 bytes to what it hashes. -
The 16-byte MD5 of what was added, after which it starts again, empty.
Sha1
class
Public Class Sha1 Implements Hasher
SHA-1's 20 bytes, only for checksums and the formats that ask for it, like Git's.
Examples
Expect(Hex.Encode(Sha1.Hash("abc")) == "a9993e364706816aba3e25717850c26c9cd0d89d")-
A new Sha1, of nothing.
-
The SHA-1 of
data. -
The SHA-1 of
text's UTF-8 bytes. -
Adds
datato what it hashes. -
Adds
text's UTF-8 bytes to what it hashes. -
The 20-byte SHA-1 of what was added, after which it starts again, empty.
Sha256
class
Public Class Sha256 Implements Hasher
SHA-256's 32 bytes.
Examples
Expect(Hex.Encode(Sha256.Hash("abc")) ==
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")
Local hasher = Sha256()
hasher.Add("ab")
hasher.Add("c".Bytes)
Expect(hasher.Finish() == Sha256.Hash("abc"))std/crypto/hashes.fb, line 141
-
A new Sha256, of nothing.
-
The SHA-256 of
data. -
The SHA-256 of
text's UTF-8 bytes. -
Adds
datato what it hashes. -
Adds
text's UTF-8 bytes to what it hashes. -
The 32-byte SHA-256 of what was added, after which it starts again, empty.
Sha512
class
Public Class Sha512 Implements Hasher
SHA-512's 64 bytes.
Examples
Expect(Sha512.Hash("abc").Count == 64)std/crypto/hashes.fb, line 179
-
A new Sha512, of nothing.
-
The SHA-512 of
data. -
The SHA-512 of
text's UTF-8 bytes. -
Adds
datato what it hashes. -
Adds
text's UTF-8 bytes to what it hashes. -
The 64-byte SHA-512 of what was added, after which it starts again, empty.
Report an issue with this page or with FutureBlitz on GitHub.