Safe Haskell | None |
---|---|
Language | Haskell98 |
A JSON Web Key (JWK) is a JavaScript Object Notation (JSON) data structure that represents a cryptographic key. This module also defines a JSON Web Key Set (JWK Set) JSON data structure for representing a set of JWKs.
-- Generate RSA JWK and set "kid" param to -- base64url-encoded SHA-256 thumbprint of key. -- doGen :: IO JWK doGen = do jwk <-genJWK
(RSAGenParam (4096 `div` 8)) let h = viewthumbprint
jwk :: Digest SHA256 kid = view (re (base64url
.digest
) . utf8) h pure $ setjwkKid
(Just kid) jwk
- genJWK :: MonadRandom m => KeyMaterialGenParam -> m JWK
- data KeyMaterialGenParam
- data Crv
- data OKPCrv
- data JWK
- class AsPublicKey k where
- jwkMaterial :: Lens' JWK KeyMaterial
- jwkUse :: Lens' JWK (Maybe KeyUse)
- data KeyUse
- jwkKeyOps :: Lens' JWK (Maybe [KeyOp])
- data KeyOp
- jwkAlg :: Lens' JWK (Maybe JWKAlg)
- data JWKAlg
- jwkKid :: Lens' JWK (Maybe Text)
- jwkX5u :: Lens' JWK (Maybe URI)
- jwkX5c :: Lens' JWK (Maybe (NonEmpty Base64X509))
- jwkX5t :: Lens' JWK (Maybe Base64SHA1)
- jwkX5tS256 :: Lens' JWK (Maybe Base64SHA256)
- fromKeyMaterial :: KeyMaterial -> JWK
- fromRSA :: PrivateKey -> JWK
- fromOctets :: Cons s s Word8 Word8 => s -> JWK
- thumbprint :: HashAlgorithm a => Getter JWK (Digest a)
- digest :: HashAlgorithm a => Prism' ByteString (Digest a)
- base64url :: (AsEmpty s1, AsEmpty s2, Cons s1 s1 Word8 Word8, Cons s2 s2 Word8 Word8) => Prism' s1 s2
- module Crypto.Hash
- newtype JWKSet = JWKSet [JWK]
- bestJWSAlg :: (MonadError e m, AsError e) => JWK -> m Alg
- module Crypto.JOSE.JWA.JWK
JWK generation
genJWK :: MonadRandom m => KeyMaterialGenParam -> m JWK Source #
Generate a JWK. Apart from key parameters, no other parameters are set.
data KeyMaterialGenParam Source #
Keygen parameters.
ECGenParam Crv | Generate an EC key with specified curve. |
RSAGenParam Int | Generate an RSA key with specified size in bytes. |
OctGenParam Int | Generate a symmetric key with specified size in bytes. |
OKPGenParam OKPCrv | Generate an EdDSA or Edwards ECDH key with specified curve. |
"crv" (Curve) Parameter
RFC 7517 §4. JSON Web Key (JWK) Format
class AsPublicKey k where Source #
Keys that may have have public material
asPublicKey :: Getter k (Maybe k) Source #
Get the public key
Parts of a JWK
RFC 7517 §4.2. "use" (Public Key Use) Parameter
RFC 7517 §4.3. "key_ops" (Key Operations) Parameter
RFC 7517 §4.4. "alg" (Algorithm) Parameter
See also RFC 7518 §6.4. which states that for "oct" keys, an "alg" member SHOULD be present to identify the algorithm intended to be used with the key, unless the application uses another means or convention to determine the algorithm used.
jwkX5tS256 :: Lens' JWK (Maybe Base64SHA256) Source #
Converting from other key formats
fromKeyMaterial :: KeyMaterial -> JWK Source #
fromRSA :: PrivateKey -> JWK Source #
Convert RSA private key into a JWK
JWK Thumbprint
thumbprint :: HashAlgorithm a => Getter JWK (Digest a) Source #
Compute the JWK Thumbprint of a JWK
digest :: HashAlgorithm a => Prism' ByteString (Digest a) Source #
Prism from ByteString to HashAlgorithm a => Digest a
.
Use
to view the bytes of a digestre
digest
base64url :: (AsEmpty s1, AsEmpty s2, Cons s1 s1 Word8 Word8, Cons s2 s2 Word8 Word8) => Prism' s1 s2 Source #
module Crypto.Hash
JWK Set
RFC 7517 §5. JWK Set Format
bestJWSAlg :: (MonadError e m, AsError e) => JWK -> m Alg Source #
Choose the cryptographically strongest JWS algorithm for a given key. The JWK "alg" algorithm parameter is ignored.
module Crypto.JOSE.JWA.JWK