Class JsonWebSecretKey

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

public final class JsonWebSecretKey extends JsonWebKey
Convenient for the handling of secret keys 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 JsonWebSecretKey.Builder of()
      Creates the default builder for a JsonWebSecretKey. Use this variant if you don't already have a secret key.
      Returns:
      a JsonWebSecretKey.Builder.
    • of

      public static JsonWebSecretKey.SecretKeyBuilder of(SecretKey secretKey)
      Creates a special builder for a JsonWebSecretKey. Use this variant if you already have a SecretKey.
      Parameters:
      secretKey - the given SecretKey
      Returns:
      a JsonWebSecretKey.SecretKeyBuilder.
      See Also:
    • getSecretKey

      public SecretKey getSecretKey()
      Returns the wrapped SecretKey.
      Returns:
      the wrapped SecretKey instance.
    • getAlgorithm

      public String getAlgorithm()
      Return the algorithm to be used with the wrapped SecretKey, e.g. HS256.
      Returns:
      the algorithm
    • toString

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

      public boolean equals(Object object)
      Compares this JsonWebSecretKey with another JsonWebSecretKey. Compares this JsonWebSecretKey with another ensuring that it contains the same configuration. Only objects of type JsonWebSecretKey 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 JsonWebSecretKey
    • hashCode

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

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

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