yajwt v1.0.1 JWT.Jws

Represent content to be secured with digital signatures or Message Authentication Codes (MACs)

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

Summary

Functions

Return a JSON Web Signature (JWS), a string representing a digitally signed payload

Return a JWS that provides no integrity protection (i.e. lacks a signature)

Return a tuple {:ok, jws (string)} if the signature is verified, or {:error, “invalid”} otherwise

Functions

sign(header, payload, key)
sign(map, binary, binary) :: binary

Return a JSON Web Signature (JWS), a string representing a digitally signed payload

Example

iex> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JWT.Jws.sign(%{alg: "HS256"}, "payload", key)
"eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4"
unsecured_message(header, payload)

Return a JWS that provides no integrity protection (i.e. lacks a signature)

Example

iex> JWT.Jws.unsecured_message(%{alg: "none"}, "payload")
"eyJhbGciOiJub25lIn0.cGF5bG9hZA."

see http://tools.ietf.org/html/rfc7515#page-47

verify(jws, algorithm, key)
verify(binary, binary, binary) ::
  {:ok, [binary]} |
  {:error, atom}

Return a tuple {:ok, jws (string)} if the signature is verified, or {:error, “invalid”} otherwise

Example

iex> jws = "eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4"
...> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JWT.Jws.verify(jws, "HS256", key)
{:ok, ["eyJhbGciOiJIUzI1NiJ9", "cGF5bG9hZA", "uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4"]}
verify!(jws, algorithm, key)
verify!(binary, binary, binary) :: [binary] | no_return