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 | 追踪IDsign- 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thealgorithmrecord component.code()Returns the value of thecoderecord component.Returns the value of theencryptedDatarecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanCheck if success 检查是否成功message()Returns the value of themessagerecord component.static EncryptedResultCreate encrypted result without signature 创建不带签名的加密响应static EncryptedResultCreate encrypted result with trace ID 创建带追踪ID的加密响应sign()Returns the value of thesignrecord component.Build the payload string for HMAC signing 构建用于HMAC签名的负载字符串Returns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.traceId()Returns the value of thetraceIdrecord component.Create a copy with sign 创建带签名的副本
-
Constructor Details
-
EncryptedResult
public EncryptedResult(String code, String message, String encryptedData, String algorithm, Instant timestamp, String traceId, String sign) Creates an instance of aEncryptedResultrecord class.- Parameters:
code- the value for thecoderecord componentmessage- the value for themessagerecord componentencryptedData- the value for theencryptedDatarecord componentalgorithm- the value for thealgorithmrecord componenttimestamp- the value for thetimestamprecord componenttraceId- the value for thetraceIdrecord componentsign- the value for thesignrecord 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
Create a copy with sign 创建带签名的副本- Parameters:
sign- the HMAC signature | HMAC签名- Returns:
- the signed encrypted result | 已签名的加密响应
-
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
-
hashCode
-
equals
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 withObjects::equals(Object,Object). -
code
-
message
-
encryptedData
Returns the value of theencryptedDatarecord component.- Returns:
- the value of the
encryptedDatarecord component
-
algorithm
-
timestamp
-
traceId
-
sign
-