Class AbstractResultEncryptor
java.lang.Object
cloud.opencode.base.web.crypto.AbstractResultEncryptor
- All Implemented Interfaces:
ResultEncryptor
- Direct Known Subclasses:
AesResultEncryptor
Abstract Result Encryptor
抽象响应加密器
Base class for result encryptors providing common functionality.
响应加密器基类,提供通用功能。
Features | 主要功能:
- Base class for result encryptors - 响应加密器基类
- JSON serialization/deserialization via OpenJson - 通过OpenJson进行JSON序列化/反序列化
- Base64 encoding of encrypted data - 加密数据的Base64编码
- Generic type support via TypeReference - 通过TypeReference支持泛型类型
- HMAC signature for tamper detection - HMAC签名防篡改
Usage Examples | 使用示例:
public class MyEncryptor extends AbstractResultEncryptor {
protected byte[] doEncrypt(byte[] data) { ... }
protected byte[] doDecrypt(byte[] data) { ... }
protected byte[] doSign(byte[] data) { ... }
public String getAlgorithm() { return "MY-ALG"; }
}
// Decrypt with generic type
Result<List<User>> result = encryptor.decrypt(encrypted, new TypeReference<List<User>>() {});
Security | 安全性:
- Thread-safe: Implementation-dependent - 取决于实现
- Null-safe: No (result must not be null) - 否(结果不能为null)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Result<T> decrypt(EncryptedResult encrypted, TypeReference<T> typeReference) Decrypt to result with generic type support 解密为带泛型类型的响应<T> Result<T> decrypt(EncryptedResult encrypted, Class<T> dataType) Decrypt to result 解密为响应protected abstract byte[]doDecrypt(byte[] data) Perform decryption 执行解密protected abstract byte[]doEncrypt(byte[] data) Perform encryption 执行加密protected abstract byte[]doSign(byte[] data) Compute HMAC signature 计算HMAC签名<T> EncryptedResultEncrypt result 加密响应Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ResultEncryptor
getAlgorithm, supports
-
Constructor Details
-
AbstractResultEncryptor
public AbstractResultEncryptor()
-
-
Method Details
-
encrypt
Description copied from interface:ResultEncryptorEncrypt result 加密响应- Specified by:
encryptin interfaceResultEncryptor- Type Parameters:
T- the data type | 数据类型- Parameters:
result- the result to encrypt | 要加密的响应- Returns:
- the encrypted result | 加密后的响应
-
decrypt
Description copied from interface:ResultEncryptorDecrypt to result 解密为响应- Specified by:
decryptin interfaceResultEncryptor- Type Parameters:
T- the data type | 数据类型- Parameters:
encrypted- the encrypted result | 加密的响应dataType- the data type class | 数据类型类- Returns:
- the decrypted result | 解密后的响应
-
decrypt
Description copied from interface:ResultEncryptorDecrypt to result with generic type support 解密为带泛型类型的响应- Specified by:
decryptin interfaceResultEncryptor- Type Parameters:
T- the data type | 数据类型- Parameters:
encrypted- the encrypted result | 加密的响应typeReference- the type reference for generic types | 泛型类型引用- Returns:
- the decrypted result | 解密后的响应
-
doEncrypt
-
doDecrypt
-
doSign
-