Class AesResultEncryptor
java.lang.Object
cloud.opencode.base.web.crypto.AbstractResultEncryptor
cloud.opencode.base.web.crypto.AesResultEncryptor
- All Implemented Interfaces:
ResultEncryptor
AES Result Encryptor
AES响应加密器
AES-GCM encryption for result data.
使用AES-GCM加密响应数据。
Security | 安全性:
- Algorithm: AES-GCM - 算法: AES-GCM
- Key size: 256 bits - 密钥长度: 256位
- IV size: 12 bytes - IV长度: 12字节
- Tag size: 128 bits - 标签长度: 128位
Features | 主要功能:
- AES-256-GCM encryption for result data - AES-256-GCM响应数据加密
- Random IV per encryption - 每次加密使用随机IV
- SHA-256 key derivation from string - 从字符串SHA-256密钥派生
- Random key generation support - 随机密钥生成支持
Usage Examples | 使用示例:
AesResultEncryptor encryptor = new AesResultEncryptor("my-secret-key");
EncryptedResult encrypted = encryptor.encrypt(result);
Result<String> decrypted = encryptor.decrypt(encrypted, String.class);
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordKey and Encryptor pair 密钥和加密器对 -
Constructor Summary
ConstructorsConstructorDescriptionAesResultEncryptor(byte[] key) Create AES encryptor with key 使用密钥创建AES加密器AesResultEncryptor(String keyString) Create AES encryptor with key string 使用密钥字符串创建AES加密器 -
Method Summary
Methods inherited from class AbstractResultEncryptor
decrypt, deserializeData, encrypt, serializeDataMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ResultEncryptor
supports
-
Constructor Details
-
AesResultEncryptor
public AesResultEncryptor(byte[] key) Create AES encryptor with key 使用密钥创建AES加密器- Parameters:
key- the encryption key (32 bytes for AES-256) | 加密密钥(AES-256需要32字节)
-
AesResultEncryptor
Create AES encryptor with key string 使用密钥字符串创建AES加密器- Parameters:
keyString- the key string (will be hashed to 32 bytes) | 密钥字符串(将被散列为32字节)
-
-
Method Details
-
getAlgorithm
Description copied from interface:ResultEncryptorGet the algorithm name 获取算法名称- Returns:
- the algorithm name | 算法名称
-
doEncrypt
Description copied from class:AbstractResultEncryptorPerform encryption 执行加密- Specified by:
doEncryptin classAbstractResultEncryptor- Parameters:
data- the data to encrypt | 要加密的数据- Returns:
- the encrypted data | 加密后的数据
- Throws:
Exception- if encryption fails | 如果加密失败
-
doDecrypt
Description copied from class:AbstractResultEncryptorPerform decryption 执行解密- Specified by:
doDecryptin classAbstractResultEncryptor- Parameters:
data- the data to decrypt | 要解密的数据- Returns:
- the decrypted data | 解密后的数据
- Throws:
Exception- if decryption fails | 如果解密失败
-
withRandomKey
Create encryptor with random key 使用随机密钥创建加密器- Returns:
- the encryptor and generated key | 加密器和生成的密钥
-