Class JsonWebKeyPair

java.lang.Object
de.christofreichardt.json.webkey.JsonWebKey
de.christofreichardt.json.webkey.JsonWebKeyPair
All Implemented Interfaces:
de.christofreichardt.diagnosis.Traceable

public final class JsonWebKeyPair extends JsonWebKey
Convenient for the handling of key pairs in the spirit of RFC 7517 (JSON Web Key) and RFC 7518 (JSON Web Algorithms).
Author:
Christof Reichardt
See Also:
  • Method Details

    • of

      public static JsonWebKeyPair.Builder of()
      Creates the default builder for a JsonWebKeyPair. Use this variant if you want to automatically create an EC key pair for curve "secp256r1".
      Returns:
      a JsonWebKeyPair.Builder.
    • of

      public static JsonWebKeyPair.KeyPairBuilder of(KeyPair keyPair)
      Creates a special builder for a JsonWebKeyPair. Use this variant if you already have a KeyPair.
      Parameters:
      keyPair - the provided KeyPair.
      Returns:
      a JsonWebKeyPair.KeyPairBuilder.
    • of

      public static JsonWebKeyPair.ParameterSpecBuilder of(AlgorithmParameterSpec algorithmParameterSpec)
      Creates a special builder for a JsonWebKeyPair. Use this variant if you want to create a KeyPair from a provided AlgorithmParameterSpec.
      Parameters:
      algorithmParameterSpec - the provided AlgorithmParameterSpec.
      Returns:
      a JsonWebKeyPair.ParameterSpecBuilder.
    • getKeyPair

      public KeyPair getKeyPair()
      Returns the actual KeyPair.
      Returns:
      the actual KeyPair.
    • getAlgorithmParameterSpec

      public AlgorithmParameterSpec getAlgorithmParameterSpec()
      Returns the applied AlgorithmParameterSpec, may be null.
      Returns:
      the applied AlgorithmParameterSpec
    • jsonWebPublicKey

      public JsonWebPublicKey jsonWebPublicKey() throws GeneralSecurityException
      Creates a JsonWebPublicKey from this JsonWebKeyPair. Firstly this JsonWebKeyPair instance will be serialized into a JsonObject and then JsonWebPublicKey.fromJson(jakarta.json.JsonObject) will be invoked.
      Returns:
      a JsonWebPublicKey
      Throws:
      GeneralSecurityException - passed through from the underlying implementations of the algorithms by the JDK.
    • toString

      public String toString()
      Returns a textual representation of this JsonWebKeyPair.
      Overrides:
      toString in class JsonWebKey
      Returns:
      a textual representation of this JsonWebKeyPair.
    • equals

      public boolean equals(Object object)
      Compares this JsonWebKeyPair with another JsonWebKeyPair. Compares this JsonWebKeyPair with another ensuring that it contains the same configuration. Only objects of type JsonWebKeyPair are considered, other types return false.
      Overrides:
      equals in class Object
      Parameters:
      object - the object to check, null returns false
      Returns:
      true if this is equal to the other JsonWebKeyPair
    • hashCode

      public int hashCode()
      A hash code for this JsonWebKeyPair.
      Overrides:
      hashCode in class Object
      Returns:
      a suitable hash code.
    • toJson

      public jakarta.json.JsonObject toJson()
      Converts this JsonWebKeyPair into a plain JsonObject.
      Overrides:
      toJson in class JsonWebKey
      Returns:
      a JsonObject corresponding to this JsonWebKeyPair.
      See Also:
    • fromJson

      public static JsonWebKeyPair fromJson(jakarta.json.JsonObject jwkView) throws GeneralSecurityException
      Factory method to create a JsonWebKeyPair instance from a plain JsonObject.
      Parameters:
      jwkView - the given JsonObject.
      Returns:
      a JsonWebKeyPair
      Throws:
      GeneralSecurityException - passed through from the underlying implementations of the algorithms by the JDK.