Base64
Bytes
Base64 encode and decode for Bytes.
encode / decode use the standard alphabet with padding. encodeUrl / decodeUrl use the URL-safe alphabet (- / _) and omit padding — the same shape JWT and many webhook APIs expect.
Values
encode
encode : Bytes -> StringEncode bytes as a standard Base64 string (with = padding).
Examples
encode (Bytes.Encode.encode (Bytes.Encode.string "hi")) == "aGk="decode
decode : String -> Maybe BytesDecode a standard Base64 string. Returns Nothing on invalid input.
Examples
decode "aGk="
|> Maybe.map (\b -> encode b) == Just "aGk="
decode "!!!" == NothingencodeUrl
encodeUrl : Bytes -> StringEncode bytes as URL-safe Base64 without padding.
Examples
encodeUrl (Bytes.Encode.encode (Bytes.Encode.string "hi")) == "aGk"decodeUrl
decodeUrl : String -> Maybe BytesDecode a URL-safe Base64 string (padding optional). Returns Nothing on invalid input.
Examples
decodeUrl "aGk"
|> Maybe.map (\b -> encode b) == Just "aGk="
decodeUrl "!!!" == Nothing