Record Class VersionedPayload
java.lang.Object
java.lang.Record
cloud.opencode.base.crypto.versioned.VersionedPayload
- Record Components:
version- the cipher version (0-255) | 加密版本号(0-255)algorithm- the algorithm name | 算法名称ciphertext- the encrypted data | 加密数据
Immutable record representing a versioned cipher payload with serialization support.
表示带版本的加密负载的不可变记录,支持序列化。
Serialization format: [1 byte version] [1 byte algorithm name length] [algorithm name UTF-8] [ciphertext]
序列化格式: [1字节版本] [1字节算法名长度] [算法名UTF8] [密文]
Features | 主要功能:
- Compact binary serialization - 紧凑的二进制序列化
- Version range 0-255 - 版本号范围 0-255
- Defensive copies of ciphertext array - 密文数组的防御性拷贝
Usage Examples | 使用示例:
VersionedPayload payload = new VersionedPayload(1, "AES-256-GCM", ciphertext);
byte[] serialized = payload.serialize();
VersionedPayload restored = VersionedPayload.deserialize(serialized);
Security | 安全性:
- Thread-safe: Yes (immutable) - 线程安全: 是(不可变)
- Since:
- JDK 25, opencode-base-crypto V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionVersionedPayload(int version, String algorithm, byte[] ciphertext) Compact constructor with parameter validation. -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thealgorithmrecord component.byte[]Returns a defensive copy of the ciphertext.static VersionedPayloaddeserialize(byte[] data) Deserializes a byte array into a VersionedPayload.booleanIndicates whether some other object is "equal to" this one.inthashCode()Returns a hash code value for this object.byte[]Serializes this payload to a byte array.toString()Returns a string representation of this record class.intversion()Returns the value of theversionrecord component.
-
Constructor Details
-
VersionedPayload
Compact constructor with parameter validation. 紧凑构造器,含参数校验。
-
-
Method Details
-
ciphertext
public byte[] ciphertext()Returns a defensive copy of the ciphertext. 返回密文的防御性拷贝。- Returns:
- copy of ciphertext bytes | 密文字节的拷贝
-
serialize
public byte[] serialize()Serializes this payload to a byte array. 将此负载序列化为字节数组。Format:
[1 byte version] [1 byte alg-name length] [alg-name UTF-8] [ciphertext]- Returns:
- serialized byte array | 序列化的字节数组
-
deserialize
Deserializes a byte array into a VersionedPayload. 将字节数组反序列化为 VersionedPayload。- Parameters:
data- the serialized data | 序列化数据- Returns:
- deserialized VersionedPayload | 反序列化的 VersionedPayload
- Throws:
OpenCryptoException- if the data is malformed | 当数据格式错误时抛出
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
hashCode
-
toString
-
version
-
algorithm
-