JsonWebToken.Jwa
Choose a cryptographic algorithm to be used for a JSON Web Signature (JWS)
Summary↑
destructured_alg(string) | Return a tuple with a valid encryption module and sha_bits; raise if |
sign(algorithm, key, signing_input) | Return a Message Authentication Code (MAC) for a particular |
verify?(mac, algorithm, key, signing_input) | Predicate to validate that |
Functions
Return a tuple with a valid encryption module and sha_bits; raise if string
is not a supported algorithm
Example
iex> JsonWebToken.Jwa.destructured_alg("HS256")
{JsonWebToken.Algorithm.Hmac, :sha256}
Return a Message Authentication Code (MAC) for a particular algorithm
Example
iex> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JsonWebToken.Jwa.sign("HS256", key, "signing_input")
<<90, 34, 44, 252, 147, 130, 167, 173, 86, 191, 247, 93, 94, 12, 200, 30, 173, 115, 248, 89, 246, 222, 4, 213, 119, 74, 70, 20, 231, 194, 104, 103>>
Predicate to validate that mac
does verify by algorithm
Example
iex> mac = <<90, 34, 44, 252, 147, 130, 167, 173, 86, 191, 247, 93, 94, 12, 200, 30, 173, 115, 248, 89, 246, 222, 4, 213, 119, 74, 70, 20, 231, 194, 104, 103>>
...> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JsonWebToken.Jwa.verify?(mac, "HS256", key, "signing_input")
true