JsonWebToken.Jws
Represent content to be secured with digital signatures or Message Authentication Codes (MACs)
Summary↑
sign(header, payload, key) | Return a JSON Web Signature (JWS), a string representing a digitally signed payload |
unsecured_message(header, payload) | Return a JWS that provides no integrity protection (i.e. lacks a signature) |
verify(jws, algorithm, key \\ nil) | Return a tuple {:ok, jws (string)} if the signature is verified, or {:error, “invalid”} otherwise |
Functions
Return a JSON Web Signature (JWS), a string representing a digitally signed payload
Example
iex> key = "gZH75aKtMN3Yj0iPS4hcgUuTwjAzZr9C"
...> JsonWebToken.Jws.sign(%{alg: "HS256"}, "payload", key)
"eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4"
Return a JWS that provides no integrity protection (i.e. lacks a signature)
Example
iex> JsonWebToken.Jws.unsecured_message(%{alg: "none"}, "payload")
"eyJhbGciOiJub25lIn0.cGF5bG9hZA."
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"
...> JsonWebToken.Jws.verify(jws, "HS256", key)
{:ok, "eyJhbGciOiJIUzI1NiJ9.cGF5bG9hZA.uVTaOdyzp_f4mT_hfzU8LnCzdmlVC4t2itHDEYUZym4"}