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

      • kid

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

        public JsonWebKey withKid​(String kid)
        Set the key identifier value.
        Parameters:
        kid - the kid value to set
        Returns:
        the JsonWebKey object itself.
      • kty

        public JsonWebKeyType kty()
        Get the kty value.
        Returns:
        the kty value
      • withKty

        public JsonWebKey withKty​(JsonWebKeyType kty)
        Set the key type value.
        Parameters:
        kty - the key type
        Returns:
        the JsonWebKey object itself.
      • withKeyOps

        public JsonWebKey withKeyOps​(List<JsonWebKeyOperation> keyOps)
        Set the keyOps value.
        Parameters:
        keyOps - the keyOps value to set
        Returns:
        the JsonWebKey object itself.
      • n

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        public JsonWebKey withQ​(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.
      • k

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

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

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

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

        public JsonWebKey withCrv​(JsonWebKeyCurveName crv)
        Set the crv value.
        Parameters:
        crv - the crv value to set
        Returns:
        the JsonWebKey object itself.
      • x

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

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

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

        public JsonWebKey withY​(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 - RSA key pair
        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 - Java security provider
        Returns:
        EC key pair
      • fromEC

        public static JsonWebKey fromEC​(KeyPair keyPair,
                                        Provider provider)
        Converts EC key pair to JSON web key.
        Parameters:
        keyPair - EC key pair
        provider - Java security provider
        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 - AES key
        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