Enum Class JwtAlgorithm

java.lang.Object
java.lang.Enum<JwtAlgorithm>
cloud.opencode.base.crypto.jwt.JwtAlgorithm
All Implemented Interfaces:
Serializable, Comparable<JwtAlgorithm>, Constable

public enum JwtAlgorithm extends Enum<JwtAlgorithm>
JWT Algorithm - Supported algorithms for JWT signing JWT 算法 - 支持的 JWT 签名算法

Features | 主要功能:

  • HMAC (HS256/384/512) algorithm definitions - HMAC(HS256/384/512)算法定义
  • RSA (RS256/384/512, PS256/384/512) algorithm definitions - RSA(RS256/384/512、PS256/384/512)算法定义
  • ECDSA (ES256/384/512) and EdDSA algorithm definitions - ECDSA(ES256/384/512)和 EdDSA 算法定义

Usage Examples | 使用示例:

JwtAlgorithm alg = JwtAlgorithm.HS256;
String jcaName = alg.jcaName();
boolean symmetric = alg.isSymmetric();

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial - 空值安全: 部分

Performance | 性能特性:

  • Time complexity: O(1) - 时间复杂度: O(1)
  • Space complexity: O(1) - 空间复杂度: O(1)
Since:
JDK 25, opencode-base-crypto V1.2.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Enum Constant Details

    • HS256

      public static final JwtAlgorithm HS256
      HMAC with SHA-256
    • HS384

      public static final JwtAlgorithm HS384
      HMAC with SHA-384
    • HS512

      public static final JwtAlgorithm HS512
      HMAC with SHA-512
    • RS256

      public static final JwtAlgorithm RS256
      RSA PKCS#1 with SHA-256
    • RS384

      public static final JwtAlgorithm RS384
      RSA PKCS#1 with SHA-384
    • RS512

      public static final JwtAlgorithm RS512
      RSA PKCS#1 with SHA-512
    • PS256

      public static final JwtAlgorithm PS256
      RSA-PSS with SHA-256
    • PS384

      public static final JwtAlgorithm PS384
      RSA-PSS with SHA-384
    • PS512

      public static final JwtAlgorithm PS512
      RSA-PSS with SHA-512
    • ES256

      public static final JwtAlgorithm ES256
      ECDSA with P-256 and SHA-256
    • ES384

      public static final JwtAlgorithm ES384
      ECDSA with P-384 and SHA-384
    • ES512

      public static final JwtAlgorithm ES512
      ECDSA with P-521 and SHA-512
    • EdDSA

      public static final JwtAlgorithm EdDSA
      EdDSA with Ed25519
  • Method Details

    • values

      public static JwtAlgorithm[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static JwtAlgorithm valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • algorithmName

      public String algorithmName()
      Returns the JWT algorithm name (e.g., "HS256", "RS256"). 返回 JWT 算法名称(例如:"HS256"、"RS256")。
      Returns:
      the algorithm name
    • jcaName

      public String jcaName()
      Returns the JCA algorithm name. 返回 JCA 算法名称。
      Returns:
      the JCA algorithm name
    • type

      public String type()
      Returns the algorithm type ("symmetric" or "asymmetric"). 返回算法类型("symmetric" 或 "asymmetric")。
      Returns:
      the algorithm type
    • isSymmetric

      public boolean isSymmetric()
      Checks if this is a symmetric algorithm. 检查是否为对称算法。
      Returns:
      true if symmetric
    • isAsymmetric

      public boolean isAsymmetric()
      Checks if this is an asymmetric algorithm. 检查是否为非对称算法。
      Returns:
      true if asymmetric
    • fromName

      public static JwtAlgorithm fromName(String name)
      Parses algorithm from string name. 从字符串名称解析算法。
      Parameters:
      name - the algorithm name
      Returns:
      the algorithm
      Throws:
      IllegalArgumentException - if algorithm is not supported