Class JSONWebKey


  • public class JSONWebKey
    extends Object
    Version:
    September 30, 2021
    Author:
    Javier Rojas Blum
    • Constructor Detail

      • JSONWebKey

        public JSONWebKey()
    • Method Detail

      • getKeyOpsType

        public List<KeyOpsType> getKeyOpsType()
        Returns key ops
        Returns:
        key ops
      • setKeyOpsType

        public void setKeyOpsType​(List<KeyOpsType> keyOpsType)
        Sets key ops
        Parameters:
        keyOpsType - key ops
      • getName

        public String getName()
        Returns the Key Name.
        Returns:
        the Key Name
      • setName

        public void setName​(String name)
        Sets the Key Name.
        Parameters:
        name - the Key Name
      • getDescr

        public String getDescr()
        Returns the Key Description.
        Returns:
        the Key Description
      • setDescr

        public void setDescr​(String description)
        Sets the Key Description.
        Parameters:
        description - the Key Description
      • getKid

        public String getKid()
        Returns the Key ID. The Key ID member can be used to match a specific key. This can be used, for instance, to choose among a set of keys within the JWK during key rollover.
        Returns:
        The Key ID.
      • setKid

        public void setKid​(String kid)
        Sets the Key ID.
        Parameters:
        kid - The Key ID.
      • setKty

        public void setKty​(KeyType kty)
      • getUse

        public Use getUse()
        Returns the intended use of the key: signature or encryption.
        Returns:
        The intended use of the key.
      • setUse

        public void setUse​(Use use)
        Sets the intended use of the key: signature or encryption.
        Parameters:
        use - The intended use of the key.
      • setAlg

        public void setAlg​(Algorithm alg)
      • getExp

        public Long getExp()
      • setExp

        public void setExp​(Long exp)
      • getCrv

        public EllipticEdvardsCurve getCrv()
        Returns the curve member that identifies the cryptographic curve used with the key.
        Returns:
        The curve member that identifies the cryptographic curve used with the key.
      • setCrv

        public void setCrv​(EllipticEdvardsCurve crv)
        Sets the curve member that identifies the cryptographic curve used with the key.
        Parameters:
        crv - The curve member that identifies the cryptographic curve used with the key.
      • setX5c

        public void setX5c​(List<String> x5c)
      • getN

        public String getN()
        Returns the modulus value for the RSA public key. It is represented as the base64url encoding of the value's representation.
        Returns:
        The modulus value for the RSA public key.
      • setN

        public void setN​(String n)
        Sets the modulus value for the RSA public key.
        Parameters:
        n - The modulus value for the RSA public key.
      • getE

        public String getE()
        Returns the exponent value for the RSA public key.
        Returns:
        The exponent value for the RSA public key.
      • setE

        public void setE​(String e)
        Sets the exponent value for the RSA public key.
        Parameters:
        e - The exponent value for the RSA public key.
      • getX

        public String getX()
        Returns the x member that contains the x coordinate for the elliptic curve point. It is represented as the base64url encoding of the coordinate's big endian representation.
        Returns:
        The x member that contains the x coordinate for the elliptic curve point.
      • setX

        public void setX​(String x)
        Sets the x member that contains the x coordinate for the elliptic curve point.
        Parameters:
        x - The x member that contains the x coordinate for the elliptic curve point.
      • getY

        public String getY()
        Returns the y member that contains the x coordinate for the elliptic curve point. It is represented as the base64url encoding of the coordinate's big endian representation.
        Returns:
        The y member that contains the x coordinate for the elliptic curve point.
      • setY

        public void setY​(String y)
        Sets the y member that contains the y coordinate for the elliptic curve point.
        Parameters:
        y - The y member that contains the y coordinate for the elliptic curve point.
      • getJwkThumbprint

        public String getJwkThumbprint()
                                throws NoSuchAlgorithmException,
                                       NoSuchProviderException,
                                       com.nimbusds.jose.jwk.JWKException
        Steps:

        1. Construct a JSON object containing only the required members of a JWK representing the key and with no whitespace or line breaks before or after any syntactic elements and with the required members ordered lexicographically by the Unicode points of the member names. (This JSON object is itself a legal JWK representation of the key.

        2. Hash the octets of the UTF-8 representation of this JSON object with a cryptographic hash function SHA-256.

        3. Encode the JKW SHA-256 Thumbprint with base64url encoding.

        Returns:
        The thumbprint of a JSON Web Key (JWK)
        Throws:
        NoSuchAlgorithmException
        NoSuchProviderException
        com.nimbusds.jose.jwk.JWKException
        See Also:
        JSON Web Key (JWK) Thumbprint
      • toJSONObject

        public org.json.JSONObject toJSONObject()
                                         throws org.json.JSONException
        Throws:
        org.json.JSONException
      • fromJSONObject

        public static JSONWebKey fromJSONObject​(org.json.JSONObject jwkJSONObject)
                                         throws org.json.JSONException
        Throws:
        org.json.JSONException