Record Class EncryptedResult

java.lang.Object
java.lang.Record
cloud.opencode.base.web.crypto.EncryptedResult
Record Components:
code - the result code | 响应码
message - the result message | 响应消息
encryptedData - the encrypted data | 加密数据
algorithm - the encryption algorithm | 加密算法
timestamp - the timestamp | 时间戳
traceId - the trace ID | 追踪ID
sign - the HMAC signature covering all fields | 覆盖所有字段的HMAC签名

public record EncryptedResult(String code, String message, String encryptedData, String algorithm, Instant timestamp, String traceId, String sign) extends Record
Encrypted Result 加密响应

Response with encrypted data payload and signature for tamper protection.

带加密数据负载和防篡改签名的响应。

Features | 主要功能:

  • Immutable encrypted result record - 不可变加密结果记录
  • Algorithm and trace ID metadata - 算法和追踪ID元数据
  • Timestamp tracking - 时间戳跟踪
  • HMAC signature for tamper detection - HMAC签名防篡改

Usage Examples | 使用示例:

EncryptedResult result = EncryptedResult.of("00000", "Success", encData, "AES-GCM");
boolean ok = result.isSuccess();
String data = result.encryptedData();
String sign = result.sign();

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 是(不可变记录)
  • Null-safe: No (code and data should not be null) - 否(响应码和数据不应为null)
Since:
JDK 25, opencode-base-web V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Details

    • EncryptedResult

      public EncryptedResult(String code, String message, String encryptedData, String algorithm, Instant timestamp, String traceId, String sign)
      Creates an instance of a EncryptedResult record class.
      Parameters:
      code - the value for the code record component
      message - the value for the message record component
      encryptedData - the value for the encryptedData record component
      algorithm - the value for the algorithm record component
      timestamp - the value for the timestamp record component
      traceId - the value for the traceId record component
      sign - the value for the sign record component
  • Method Details

    • of

      public static EncryptedResult of(String code, String message, String encryptedData, String algorithm)
      Create encrypted result without signature 创建不带签名的加密响应
      Parameters:
      code - the result code | 响应码
      message - the result message | 响应消息
      encryptedData - the encrypted data | 加密数据
      algorithm - the encryption algorithm | 加密算法
      Returns:
      the encrypted result | 加密响应
    • of

      public static EncryptedResult of(String code, String message, String encryptedData, String algorithm, String traceId)
      Create encrypted result with trace ID 创建带追踪ID的加密响应
      Parameters:
      code - the result code | 响应码
      message - the result message | 响应消息
      encryptedData - the encrypted data | 加密数据
      algorithm - the encryption algorithm | 加密算法
      traceId - the trace ID | 追踪ID
      Returns:
      the encrypted result | 加密响应
    • withSign

      public EncryptedResult withSign(String sign)
      Create a copy with sign 创建带签名的副本
      Parameters:
      sign - the HMAC signature | HMAC签名
      Returns:
      the signed encrypted result | 已签名的加密响应
    • signPayload

      public String signPayload()
      Build the payload string for HMAC signing 构建用于HMAC签名的负载字符串

      Concatenates all fields except sign in a deterministic order.

      按确定性顺序拼接除sign之外的所有字段。

      Returns:
      the payload string | 负载字符串
    • isSuccess

      public boolean isSuccess()
      Check if success 检查是否成功
      Returns:
      true if success | 如果成功返回true
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • code

      public String code()
      Returns the value of the code record component.
      Returns:
      the value of the code record component
    • message

      public String message()
      Returns the value of the message record component.
      Returns:
      the value of the message record component
    • encryptedData

      public String encryptedData()
      Returns the value of the encryptedData record component.
      Returns:
      the value of the encryptedData record component
    • algorithm

      public String algorithm()
      Returns the value of the algorithm record component.
      Returns:
      the value of the algorithm record component
    • timestamp

      public Instant timestamp()
      Returns the value of the timestamp record component.
      Returns:
      the value of the timestamp record component
    • traceId

      public String traceId()
      Returns the value of the traceId record component.
      Returns:
      the value of the traceId record component
    • sign

      public String sign()
      Returns the value of the sign record component.
      Returns:
      the value of the sign record component