json_web_token v0.2.10 JsonWebToken.Jwa

Choose a cryptographic algorithm to be used for a JSON Web Signature (JWS)

see http://tools.ietf.org/html/rfc7518

Link to this section Summary

Functions

Return a tuple with a valid encryption module and sha_bits; raise if string is not a supported algorithm

Return a Message Authentication Code (MAC) for a particular algorithm

Predicate to validate that mac does verify by algorithm

Link to this section Functions

Link to this function destructured_alg(string)

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}
Link to this function sign(algorithm, key, signing_input)

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>>
Link to this function verify?(mac, algorithm, key, signing_input)

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