Class KeyType

  • All Implemented Interfaces:
    java.io.Serializable

    @Immutable
    public final class KeyType
    extends java.lang.Object
    implements java.io.Serializable
    Key type. Represents the kty parameter in a JSON Web Key (JWK). This class is immutable.

    Includes constants for the following standard key types:

    Additional key types can be defined using the constructor.

    Version:
    2017-08-23
    Author:
    Vladimir Dzhuvinov, Justin Richer
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static KeyType EC
      Elliptic Curve (DSS) key type (recommended).
      static KeyType OCT
      Octet sequence key type (optional).
      static KeyType OKP
      Octet key pair (optional).
      static KeyType RSA
      RSA (RFC 3447) key type (required).
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyType​(java.lang.String value, Requirement req)
      Creates a new key type with the specified value and implementation requirement.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object object)
      Overrides Object.equals().
      static KeyType forAlgorithm​(Algorithm alg)
      Infers the key type for the specified JOSE algorithm.
      Requirement getRequirement()
      Gets the implementation requirement of this key type.
      java.lang.String getValue()
      Gets the value of this key type.
      int hashCode()
      Overrides Object.hashCode().
      static KeyType parse​(java.lang.String s)
      Parses a key type from the specified kty parameter value.
      java.lang.String toJSONString()
      Returns the JSON string representation of this key type.
      java.lang.String toString()
      Returns the string representation of this key type.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • EC

        public static final KeyType EC
        Elliptic Curve (DSS) key type (recommended).
      • RSA

        public static final KeyType RSA
        RSA (RFC 3447) key type (required).
      • OCT

        public static final KeyType OCT
        Octet sequence key type (optional).
      • OKP

        public static final KeyType OKP
        Octet key pair (optional).
    • Constructor Detail

      • KeyType

        public KeyType​(java.lang.String value,
                       Requirement req)
        Creates a new key type with the specified value and implementation requirement.
        Parameters:
        value - The key type value. Values are case sensitive. Must not be null.
        req - The implementation requirement, null if not known.
    • Method Detail

      • getValue

        public java.lang.String getValue()
        Gets the value of this key type. Values are case sensitive.
        Returns:
        The key type.
      • getRequirement

        public Requirement getRequirement()
        Gets the implementation requirement of this key type.
        Returns:
        The implementation requirement, null if not known.
      • hashCode

        public int hashCode()
        Overrides Object.hashCode().
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        The object hash code.
      • equals

        public boolean equals​(java.lang.Object object)
        Overrides Object.equals().
        Overrides:
        equals in class java.lang.Object
        Parameters:
        object - The object to compare to.
        Returns:
        true if the objects have the same value, otherwise false.
      • toString

        public java.lang.String toString()
        Returns the string representation of this key type.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string representation.
        See Also:
        getValue()
      • toJSONString

        public java.lang.String toJSONString()
        Returns the JSON string representation of this key type.
        Returns:
        The JSON string representation.
      • parse

        public static KeyType parse​(java.lang.String s)
        Parses a key type from the specified kty parameter value.
        Parameters:
        s - The string to parse. Must not be null.
        Returns:
        The key type (matching standard key type constant, else a newly created one).
      • forAlgorithm

        public static KeyType forAlgorithm​(Algorithm alg)
        Infers the key type for the specified JOSE algorithm.
        Parameters:
        alg - The JOSE algorithm. May be null.
        Returns:
        The key type, null if it couldn't be inferred.