Class OpenCryptoException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
cloud.opencode.base.crypto.exception.OpenCryptoException
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
PolicyViolationException

public class OpenCryptoException extends RuntimeException
Base exception for cryptographic operations - Runtime exception for encryption/decryption failures 加密组件基础异常 - 加密/解密操作失败时的运行时异常

Features | 主要功能:

  • Algorithm and operation context in error messages - 错误消息中包含算法和操作上下文
  • Factory methods for common error scenarios - 常见错误场景的工厂方法

Usage Examples | 使用示例:

throw new OpenCryptoException("AES", "encrypt", "Key not set");
throw new OpenCryptoException("Operation failed", cause);

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Null-safe: Partial - 空值安全: 部分
Since:
JDK 25, opencode-base-crypto V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • OpenCryptoException

      public OpenCryptoException(String message)
      Constructs a new OpenCryptoException with the specified message. 使用指定消息构造新的加密异常
      Parameters:
      message - the detail message
    • OpenCryptoException

      public OpenCryptoException(String message, Throwable cause)
      Constructs a new OpenCryptoException with the specified message and cause. 使用指定消息和原因构造新的加密异常
      Parameters:
      message - the detail message
      cause - the cause
    • OpenCryptoException

      public OpenCryptoException(String algorithm, String operation, String message)
      Constructs a new OpenCryptoException with algorithm, operation and message. 使用算法、操作和消息构造新的加密异常
      Parameters:
      algorithm - the cryptographic algorithm
      operation - the operation being performed
      message - the detail message
    • OpenCryptoException

      public OpenCryptoException(String algorithm, String operation, String message, Throwable cause)
      Constructs a new OpenCryptoException with algorithm, operation, message and cause. 使用算法、操作、消息和原因构造新的加密异常
      Parameters:
      algorithm - the cryptographic algorithm
      operation - the operation being performed
      message - the detail message
      cause - the cause
  • Method Details

    • algorithm

      public String algorithm()
      Returns the cryptographic algorithm associated with this exception. 返回与此异常关联的加密算法
      Returns:
      the algorithm, or null if not specified
    • operation

      public String operation()
      Returns the operation being performed when this exception occurred. 返回发生异常时正在执行的操作
      Returns:
      the operation, or null if not specified
    • algorithmNotAvailable

      public static OpenCryptoException algorithmNotAvailable(String algorithm)
      Creates an exception for when a cryptographic algorithm is not available. 创建加密算法不可用时的异常
      Parameters:
      algorithm - the unavailable algorithm
      Returns:
      a new OpenCryptoException
    • encryptionFailed

      public static OpenCryptoException encryptionFailed(String algorithm, Throwable cause)
      Creates an exception for encryption failures. 创建加密失败时的异常
      Parameters:
      algorithm - the encryption algorithm
      cause - the underlying cause
      Returns:
      a new OpenCryptoException
    • decryptionFailed

      public static OpenCryptoException decryptionFailed(String algorithm, Throwable cause)
      Creates an exception for decryption failures. 创建解密失败时的异常
      Parameters:
      algorithm - the decryption algorithm
      cause - the underlying cause
      Returns:
      a new OpenCryptoException
    • authenticationFailed

      public static OpenCryptoException authenticationFailed(String algorithm)
      Creates an exception for authentication failures. 创建身份验证失败时的异常
      Parameters:
      algorithm - the authentication algorithm
      Returns:
      a new OpenCryptoException
    • paddingError

      public static OpenCryptoException paddingError(String algorithm)
      Creates an exception for padding errors. 创建填充错误时的异常
      Parameters:
      algorithm - the algorithm with padding error
      Returns:
      a new OpenCryptoException
    • invalidIv

      public static OpenCryptoException invalidIv(String algorithm, int expected, int actual)
      Creates an exception for invalid initialization vector (IV). 创建无效初始化向量时的异常
      Parameters:
      algorithm - the algorithm requiring IV
      expected - the expected IV length
      actual - the actual IV length
      Returns:
      a new OpenCryptoException
    • dataTooLong

      public static OpenCryptoException dataTooLong(String algorithm, int maxSize)
      Creates an exception for data that exceeds maximum size. 创建数据超过最大长度时的异常
      Parameters:
      algorithm - the algorithm with size limitation
      maxSize - the maximum allowed size
      Returns:
      a new OpenCryptoException