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
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 Summary
ConstructorsConstructorDescriptionOpenCryptoException(String message) Constructs a new OpenCryptoException with the specified message.OpenCryptoException(String algorithm, String operation, String message) Constructs a new OpenCryptoException with algorithm, operation and message.OpenCryptoException(String algorithm, String operation, String message, Throwable cause) Constructs a new OpenCryptoException with algorithm, operation, message and cause.OpenCryptoException(String message, Throwable cause) Constructs a new OpenCryptoException with the specified message and cause. -
Method Summary
Modifier and TypeMethodDescriptionReturns the cryptographic algorithm associated with this exception.static OpenCryptoExceptionalgorithmNotAvailable(String algorithm) Creates an exception for when a cryptographic algorithm is not available.static OpenCryptoExceptionauthenticationFailed(String algorithm) Creates an exception for authentication failures.static OpenCryptoExceptiondataTooLong(String algorithm, int maxSize) Creates an exception for data that exceeds maximum size.static OpenCryptoExceptiondecryptionFailed(String algorithm, Throwable cause) Creates an exception for decryption failures.static OpenCryptoExceptionencryptionFailed(String algorithm, Throwable cause) Creates an exception for encryption failures.static OpenCryptoExceptionCreates an exception for invalid initialization vector (IV).Returns the operation being performed when this exception occurred.static OpenCryptoExceptionpaddingError(String algorithm) Creates an exception for padding errors.Methods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
OpenCryptoException
Constructs a new OpenCryptoException with the specified message. 使用指定消息构造新的加密异常- Parameters:
message- the detail message
-
OpenCryptoException
-
OpenCryptoException
-
OpenCryptoException
Constructs a new OpenCryptoException with algorithm, operation, message and cause. 使用算法、操作、消息和原因构造新的加密异常- Parameters:
algorithm- the cryptographic algorithmoperation- the operation being performedmessage- the detail messagecause- the cause
-
-
Method Details
-
algorithm
Returns the cryptographic algorithm associated with this exception. 返回与此异常关联的加密算法- Returns:
- the algorithm, or null if not specified
-
operation
Returns the operation being performed when this exception occurred. 返回发生异常时正在执行的操作- Returns:
- the operation, or null if not specified
-
algorithmNotAvailable
Creates an exception for when a cryptographic algorithm is not available. 创建加密算法不可用时的异常- Parameters:
algorithm- the unavailable algorithm- Returns:
- a new OpenCryptoException
-
encryptionFailed
Creates an exception for encryption failures. 创建加密失败时的异常- Parameters:
algorithm- the encryption algorithmcause- the underlying cause- Returns:
- a new OpenCryptoException
-
decryptionFailed
Creates an exception for decryption failures. 创建解密失败时的异常- Parameters:
algorithm- the decryption algorithmcause- the underlying cause- Returns:
- a new OpenCryptoException
-
authenticationFailed
Creates an exception for authentication failures. 创建身份验证失败时的异常- Parameters:
algorithm- the authentication algorithm- Returns:
- a new OpenCryptoException
-
paddingError
Creates an exception for padding errors. 创建填充错误时的异常- Parameters:
algorithm- the algorithm with padding error- Returns:
- a new OpenCryptoException
-
invalidIv
Creates an exception for invalid initialization vector (IV). 创建无效初始化向量时的异常- Parameters:
algorithm- the algorithm requiring IVexpected- the expected IV lengthactual- the actual IV length- Returns:
- a new OpenCryptoException
-
dataTooLong
Creates an exception for data that exceeds maximum size. 创建数据超过最大长度时的异常- Parameters:
algorithm- the algorithm with size limitationmaxSize- the maximum allowed size- Returns:
- a new OpenCryptoException
-