Class AbstractResultEncryptor

java.lang.Object
cloud.opencode.base.web.crypto.AbstractResultEncryptor
All Implemented Interfaces:
ResultEncryptor
Direct Known Subclasses:
AesResultEncryptor

public abstract class AbstractResultEncryptor extends Object implements ResultEncryptor
Abstract Result Encryptor 抽象响应加密器

Base class for result encryptors providing common functionality.

响应加密器基类,提供通用功能。

Features | 主要功能:

  • Base class for result encryptors - 响应加密器基类
  • JSON serialization/deserialization - JSON序列化/反序列化
  • Base64 encoding of encrypted data - 加密数据的Base64编码

Usage Examples | 使用示例:

public class MyEncryptor extends AbstractResultEncryptor {
    protected byte[] doEncrypt(byte[] data) { ... }
    protected byte[] doDecrypt(byte[] data) { ... }
    public String getAlgorithm() { return "MY-ALG"; }
}

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 Details

    • AbstractResultEncryptor

      public AbstractResultEncryptor()
  • Method Details

    • encrypt

      public <T> EncryptedResult encrypt(Result<T> result)
      Description copied from interface: ResultEncryptor
      Encrypt result 加密响应
      Specified by:
      encrypt in interface ResultEncryptor
      Type Parameters:
      T - the data type | 数据类型
      Parameters:
      result - the result to encrypt | 要加密的响应
      Returns:
      the encrypted result | 加密后的响应
    • decrypt

      public <T> Result<T> decrypt(EncryptedResult encrypted, Class<T> dataType)
      Description copied from interface: ResultEncryptor
      Decrypt to result 解密为响应
      Specified by:
      decrypt in interface ResultEncryptor
      Type Parameters:
      T - the data type | 数据类型
      Parameters:
      encrypted - the encrypted result | 加密的响应
      dataType - the data type class | 数据类型类
      Returns:
      the decrypted result | 解密后的响应
    • doEncrypt

      protected abstract byte[] doEncrypt(byte[] data) throws Exception
      Perform encryption 执行加密
      Parameters:
      data - the data to encrypt | 要加密的数据
      Returns:
      the encrypted data | 加密后的数据
      Throws:
      Exception - if encryption fails | 如果加密失败
    • doDecrypt

      protected abstract byte[] doDecrypt(byte[] data) throws Exception
      Perform decryption 执行解密
      Parameters:
      data - the data to decrypt | 要解密的数据
      Returns:
      the decrypted data | 解密后的数据
      Throws:
      Exception - if decryption fails | 如果解密失败
    • serializeData

      protected String serializeData(Object data)
      Serialize data to JSON string 将数据序列化为JSON字符串

      Override this method to use custom serialization.

      重写此方法以使用自定义序列化。

      Parameters:
      data - the data to serialize | 要序列化的数据
      Returns:
      the JSON string | JSON字符串
    • deserializeData

      protected <T> T deserializeData(String json, Class<T> dataType)
      Deserialize JSON string to data 将JSON字符串反序列化为数据

      Override this method to use custom deserialization.

      重写此方法以使用自定义反序列化。

      Type Parameters:
      T - the data type | 数据类型
      Parameters:
      json - the JSON string | JSON字符串
      dataType - the data type | 数据类型
      Returns:
      the deserialized data | 反序列化的数据