Class JSONWebKey


  • public class JSONWebKey
    extends java.lang.Object
    Version:
    September 30, 2021
    Author:
    Javier Rojas Blum
    • Constructor Summary

      Constructors 
      Constructor Description
      JSONWebKey()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static JSONWebKey fromJSONObject​(org.json.JSONObject jwkJSONObject)  
      Algorithm getAlg()  
      EllipticEdvardsCurve getCrv()
      Returns the curve member that identifies the cryptographic curve used with the key.
      java.lang.String getE()
      Returns the exponent value for the RSA public key.
      java.lang.Long getExp()  
      java.lang.String getJwkThumbprint()
      Steps:
      java.lang.String getKid()
      Returns the Key ID.
      KeyType getKty()  
      java.lang.String getN()
      Returns the modulus value for the RSA public key.
      Use getUse()
      Returns the intended use of the key: signature or encryption.
      java.lang.String getX()
      Returns the x member that contains the x coordinate for the elliptic curve point.
      java.util.List<java.lang.String> getX5c()  
      java.lang.String getY()
      Returns the y member that contains the x coordinate for the elliptic curve point.
      void setAlg​(Algorithm alg)  
      void setCrv​(EllipticEdvardsCurve crv)
      Sets the curve member that identifies the cryptographic curve used with the key.
      void setE​(java.lang.String e)
      Sets the exponent value for the RSA public key.
      void setExp​(java.lang.Long exp)  
      void setKid​(java.lang.String kid)
      Sets the Key ID.
      void setKty​(KeyType kty)  
      void setN​(java.lang.String n)
      Sets the modulus value for the RSA public key.
      void setUse​(Use use)
      Sets the intended use of the key: signature or encryption.
      void setX​(java.lang.String x)
      Sets the x member that contains the x coordinate for the elliptic curve point.
      void setX5c​(java.util.List<java.lang.String> x5c)  
      void setY​(java.lang.String y)
      Sets the y member that contains the y coordinate for the elliptic curve point.
      org.json.JSONObject toJSONObject()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JSONWebKey

        public JSONWebKey()
    • Method Detail

      • getKid

        public java.lang.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​(java.lang.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 java.lang.Long getExp()
      • setExp

        public void setExp​(java.lang.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.
      • getX5c

        public java.util.List<java.lang.String> getX5c()
      • setX5c

        public void setX5c​(java.util.List<java.lang.String> x5c)
      • getN

        public java.lang.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​(java.lang.String n)
        Sets the modulus value for the RSA public key.
        Parameters:
        n - The modulus value for the RSA public key.
      • getE

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

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

        public java.lang.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​(java.lang.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 java.lang.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​(java.lang.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 java.lang.String getJwkThumbprint()
                                          throws java.security.NoSuchAlgorithmException,
                                                 java.security.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:
        java.security.NoSuchAlgorithmException
        java.security.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