Class Jwk

java.lang.Object
com.revetsec.jose.Jwk

@Immutable public final class Jwk extends Object
One usable public key from a Jwks: an RSA, EC (P-256, P-384 or P-521) or Ed25519 key that passed every rule for verifying JWS signatures (see JwkSkipReason).

Instances exist only for such keys, so there is no public factory: they come from Jwks.getKeys(). This class describes the key; it holds no private key material and exposes no JCA key.

Equality is by value: the RFC 7638 thumbprint, which identifies the key material, and the kid, alg and use members, and also the key's JWK issuer member, which this class does not expose but which decides the tokens the key may verify. toString() shows the key ID with its control characters escaped, the key type, curve and algorithm, and the thumbprint.

Since:
1.0.0
Author:
Mark Allen
  • Method Details

    • getKeyId

      Returns the key ID (kid, RFC 7517 section 4.5).
      Returns:
      the key ID, 1 to 256 characters, or empty if the key has none
      Since:
      1.0.0
    • getKeyType

      Returns the key type (kty, RFC 7517 section 4.1).
      Returns:
      RSA, EC or OKP
      Since:
      1.0.0
    • getCurve

      Returns the curve (crv; RFC 7518 section 6.2.1.1, RFC 8037 section 2).
      Returns:
      P-256, P-384, P-521 or Ed25519, or empty for an RSA key
      Since:
      1.0.0
    • getAlgorithm

      Returns the algorithm the key is restricted to (alg, RFC 7517 section 4.4). A key with an algorithm verifies only that algorithm, except that JwsAlgorithm.EDDSA and JwsAlgorithm.ED25519 verify each other; an RSA key without one verifies only while exactly one RSA algorithm is allowed.
      Returns:
      the algorithm, or empty if the key has none
      Since:
      1.0.0
    • getUse

      Returns the key's intended use (use, RFC 7517 section 4.2).
      Returns:
      sig, or empty if the key has no use member
      Since:
      1.0.0
    • getThumbprintSha256

      Returns the key's RFC 7638 JWK thumbprint with SHA-256, which identifies the key material whatever its other members say.
      Returns:
      the thumbprint, in unpadded base64url (43 characters)
      Since:
      1.0.0
    • equals

      public boolean equals(@Nullable Object object)
      Compares by value: the thumbprint, key ID, algorithm, use and the JWK issuer member.
      Overrides:
      equals in class Object
      Parameters:
      object - the other object
      Returns:
      whether object is an equal key
      Since:
      1.0.0
    • hashCode

      public int hashCode()
      Returns a hash of the thumbprint.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
      Since:
      1.0.0
    • toString

      Describes the key by its public facts. The key ID comes from the key set's author, so its control characters, quotation marks, backslashes and bidirectional formatting characters are escaped.
      Overrides:
      toString in class Object
      Returns:
      the description
      Since:
      1.0.0