Class JsonWebKey


  • public class JsonWebKey
    extends Object
    As of http://tools.ietf.org/html/draft-ietf-jose-json-web-key-18.
    • Constructor Detail

      • JsonWebKey

        public JsonWebKey()
    • Method Detail

      • getId

        public String getId()
        Get the kid value.
        Returns:
        the kid value
      • setId

        public JsonWebKey setId​(String keyId)
        Set the key identifier value.
        Parameters:
        keyId - The keyId value to set
        Returns:
        the JsonWebKey object itself.
      • getKeyType

        public KeyType getKeyType()
        Get the kty value.
        Returns:
        the kty value
      • setKeyType

        public JsonWebKey setKeyType​(KeyType keyType)
        Set the key type value.
        Parameters:
        keyType - The key type
        Returns:
        the JsonWebKey object itself.
      • getKeyOps

        public List<KeyOperation> getKeyOps()
        Get the immutable key operations list. The list cannot be modified.
        Returns:
        the key operations list
      • setKeyOps

        public JsonWebKey setKeyOps​(List<KeyOperation> keyOps)
        Set the keyOps value.
        Parameters:
        keyOps - The keyOps value to set
        Returns:
        the JsonWebKey object itself.
      • getN

        public byte[] getN()
        Get the n value.
        Returns:
        the n value
      • setN

        public JsonWebKey setN​(byte[] n)
        Set the n value.
        Parameters:
        n - The n value to set
        Returns:
        the JsonWebKey object itself.
      • getE

        public byte[] getE()
        Get the e value.
        Returns:
        the e value
      • setE

        public JsonWebKey setE​(byte[] e)
        Set the e value.
        Parameters:
        e - The e value to set
        Returns:
        the JsonWebKey object itself.
      • getD

        public byte[] getD()
        Get the d value.
        Returns:
        the d value
      • setD

        public JsonWebKey setD​(byte[] d)
        Set the d value.
        Parameters:
        d - The d value to set
        Returns:
        the JsonWebKey object itself.
      • getDp

        public byte[] getDp()
        Get the RSA Private Key Parameter value.
        Returns:
        the RSA Private Key Parameter value.
      • setDp

        public JsonWebKey setDp​(byte[] dp)
        Set RSA Private Key Parameter value.
        Parameters:
        dp - The RSA Private Key Parameter value to set.
        Returns:
        the JsonWebKey object itself.
      • getDq

        public byte[] getDq()
        Get the RSA Private Key Parameter value.
        Returns:
        the RSA Private Key Parameter value.
      • setDq

        public JsonWebKey setDq​(byte[] dq)
        Set RSA Private Key Parameter value .
        Parameters:
        dq - The RSA Private Key Parameter value to set.
        Returns:
        the JsonWebKey object itself.
      • getQi

        public byte[] getQi()
        Get the RSA Private Key Parameter value.
        Returns:
        the RSA Private Key Parameter value.
      • setQi

        public JsonWebKey setQi​(byte[] qi)
        Set RSA Private Key Parameter value.
        Parameters:
        qi - The RSA Private Key Parameter value to set.
        Returns:
        the JsonWebKey object itself.
      • getP

        public byte[] getP()
        Get the RSA secret prime value.
        Returns:
        the RSA secret prime value.
      • setP

        public JsonWebKey setP​(byte[] p)
        Set the RSA secret prime value.
        Parameters:
        p - The RSA secret prime value.
        Returns:
        the JsonWebKey object itself.
      • getQ

        public byte[] getQ()
        Get RSA secret prime, with p < q value.
        Returns:
        the RSA secret prime, with p < q value.
      • setQ

        public JsonWebKey setQ​(byte[] q)
        Set the RSA secret prime, with p < q value.
        Parameters:
        q - The the RSA secret prime, with p < q value to be set.
        Returns:
        the JsonWebKey object itself.
      • getK

        public byte[] getK()
        Get Symmetric key value.
        Returns:
        the symmetric key value.
      • setK

        public JsonWebKey setK​(byte[] k)
        Set the Symmetric key value.
        Parameters:
        k - The symmetric key value to set.
        Returns:
        the JsonWebKey object itself.
      • getT

        public byte[] getT()
        Get HSM Token value, used with Bring Your Own Key.
        Returns:
        HSM Token, used with Bring Your Own Key.
      • setT

        public JsonWebKey setT​(byte[] t)
        Set HSM Token value, used with Bring Your Own Key.
        Parameters:
        t - The HSM Token value to set, used with Bring Your Own Key
        Returns:
        the JsonWebKey object itself.
      • getCurveName

        public KeyCurveName getCurveName()
        Get the crv value.
        Returns:
        the crv value
      • setCurveName

        public JsonWebKey setCurveName​(KeyCurveName crv)
        Set the crv value.
        Parameters:
        crv - The crv value to set
        Returns:
        the JsonWebKey object itself.
      • getX

        public byte[] getX()
        Get the x value.
        Returns:
        the x value
      • setX

        public JsonWebKey setX​(byte[] x)
        Set the x value.
        Parameters:
        x - The x value to set
        Returns:
        the JsonWebKey object itself.
      • getY

        public byte[] getY()
        Get the y value.
        Returns:
        the y value
      • setY

        public JsonWebKey setY​(byte[] y)
        Set the y value.
        Parameters:
        y - The y value to set
        Returns:
        the JsonWebKey object itself.
      • fromRsa

        public static JsonWebKey fromRsa​(KeyPair keyPair)
        Converts RSA key pair to JSON web key.
        Parameters:
        keyPair - Tbe RSA key pair
        Returns:
        the JSON web key, converted from RSA key pair.
      • fromRsa

        public static JsonWebKey fromRsa​(KeyPair keyPair,
                                         List<KeyOperation> keyOperations)
        Converts RSA key pair to JSON web key.
        Parameters:
        keyPair - Tbe RSA key pair
        keyOperations - The key operations to set on the key
        Returns:
        the JSON web key, converted from RSA key pair.
      • toRsa

        public KeyPair toRsa()
        Converts JSON web key to RSA key pair.
        Returns:
        RSA key pair
      • toRsa

        public KeyPair toRsa​(boolean includePrivateParameters)
        Converts JSON web key to RSA key pair and include the private key if set to true.
        Parameters:
        includePrivateParameters - true if the RSA key pair should include the private key. False otherwise.
        Returns:
        RSA key pair
      • toRsa

        public KeyPair toRsa​(boolean includePrivateParameters,
                             Provider provider)
        Converts JSON web key to RSA key pair and include the private key if set to true.
        Parameters:
        provider - The Java security provider.
        includePrivateParameters - true if the RSA key pair should include the private key. False otherwise.
        Returns:
        RSA key pair
      • toEc

        public KeyPair toEc()
        Converts JSON web key to EC key pair and include the private key if set to true.
        Returns:
        EC key pair
      • toEc

        public KeyPair toEc​(boolean includePrivateParameters)
        Converts JSON web key to EC key pair and include the private key if set to true.
        Parameters:
        includePrivateParameters - true if the EC key pair should include the private key. False otherwise.
        Returns:
        EC key pair
      • toEc

        public KeyPair toEc​(boolean includePrivateParameters,
                            Provider provider)
        Converts JSON web key to EC key pair and include the private key if set to true.
        Parameters:
        includePrivateParameters - true if the EC key pair should include the private key. False otherwise.
        provider - The Java security provider
        Returns:
        EC key pair
        Throws:
        IllegalArgumentException - if the key type is not EC or EC HSM
        IllegalStateException - if an instance of EC key pair cannot be generated
      • fromEc

        public static JsonWebKey fromEc​(KeyPair keyPair,
                                        Provider provider)
        Converts EC key pair to JSON web key.
        Parameters:
        keyPair - The EC key pair
        provider - The Java security provider
        Returns:
        the JSON web key, converted from EC key pair.
      • fromEc

        public static JsonWebKey fromEc​(KeyPair keyPair,
                                        Provider provider,
                                        List<KeyOperation> keyOperations)
        Converts EC key pair to JSON web key.
        Parameters:
        keyPair - The EC key pair
        provider - The Java security provider
        keyOperations - The key operations to set.
        Returns:
        the JSON web key, converted from EC key pair.
      • fromAes

        public static JsonWebKey fromAes​(SecretKey secretKey)
        Converts AES key to JSON web key.
        Parameters:
        secretKey - The AES key
        Returns:
        the JSON web key, converted from AES key.
      • fromAes

        public static JsonWebKey fromAes​(SecretKey secretKey,
                                         List<KeyOperation> keyOperations)
        Converts AES key to JSON web key.
        Parameters:
        secretKey - The AES key
        keyOperations - The key operations to set
        Returns:
        the JSON web key, converted from AES key.
      • toAes

        public SecretKey toAes()
        Converts JSON web key to AES key.
        Returns:
        AES key
      • equals

        public boolean equals​(JsonWebKey jwk)
        Indicates whether some other JsonWebKey is "equal to" this one.
        Parameters:
        jwk - The other JsonWebKey to compare with.
        Returns:
        true if this JsonWebKey is the same as the jwk argument; false otherwise.
      • hasPrivateKey

        public boolean hasPrivateKey()
        Verifies whether the JsonWebKey has private key.
        Returns:
        true if the JsonWebKey has private key; false otherwise.
      • isValid

        public boolean isValid()
        Verifies whether the JsonWebKey is valid.
        Returns:
        true if the JsonWebKey is valid; false otherwise.
      • clearMemory

        public void clearMemory()
        Clear key materials.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object