elm-cardano/blake2b/2.0.0

Blake2b

BLAKE2b is a cryptographic hash function (RFC 7693) that supports keyed hashing and variable-length output (1 to 64 bytes).

For fixed-length unkeyed hashes, prefer the dedicated modules Blake2b224, Blake2b256, or Blake2b512.

type Digest

An abstract BLAKE2b digest. Its length matches the digestLength passed to the constructor.

Creating digests

{ digestLength : Int
, key : Bytes
}
-> String
-> Digest

Create a digest from a String.

digestLength is the output length in bytes (1 to 64). Use empty Bytes as key for unkeyed hashing, or a 1-to-64 byte key for a keyed hash (MAC).

import Blake2b
import Bytes.Encode as Encode


Blake2b.fromString
    { digestLength = 32, key = Encode.encode (Encode.sequence []) }
    "hello"
    |> Blake2b.toHex
--> "324dcf027dd4a30a932c441f365a25e86b173defa4b8e58948253471b81b72cf"
{ digestLength : Int
, key : Bytes
}
-> Bytes
-> Digest

Create a digest from Bytes.

{ digestLength : Int
, key : Bytes
}
-> List Int
-> Digest

Create a digest from a list of byte values (0-255).

Formatting digests

toHex : Digest -> String

Turn a digest into a hex string.

toBase64 : Digest -> String

Turn a digest into a base64 encoded string.

To binary data

toBytes : Digest -> Bytes

Turn a digest into Bytes. Width matches the digestLength used at construction time.

toByteValues : Digest -> List Int

Turn a digest into a list of byte values (0-255).