Class EncryptedEnvelope
java.lang.Object
cloud.opencode.base.crypto.envelope.EncryptedEnvelope
Encrypted envelope data structure - Contains encrypted key, IV, ciphertext and authentication tag
加密信封数据结构 - 包含加密密钥、初始化向量、密文和认证标签
Features | 主要功能:
- Encrypted data container with metadata - 带元数据的加密数据容器
Usage Examples | 使用示例:
EncryptedEnvelope envelope = new EncryptedEnvelope(wrappedKey, ciphertext, iv);
Security | 安全性:
- Thread-safe: Yes - 线程安全: 是
- Null-safe: Yes - 空值安全: 是
- Since:
- JDK 25, opencode-base-crypto V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionEncryptedEnvelope(byte[] encryptedKey, byte[] iv, byte[] ciphertext, byte[] tag) Constructs an encrypted envelope with the specified components. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]Returns the ciphertext.byte[]Returns the encrypted data encryption key.booleanstatic EncryptedEnvelopefromBase64(String base64) Deserializes an encrypted envelope from a Base64 encoded string.static EncryptedEnvelopefromBytes(byte[] bytes) Deserializes an encrypted envelope from a byte array.inthashCode()byte[]iv()Returns the initialization vector.byte[]tag()Returns the authentication tag.toBase64()Serializes this envelope to a Base64 encoded string.byte[]toBytes()Serializes this envelope to a byte array.toString()
-
Constructor Details
-
EncryptedEnvelope
public EncryptedEnvelope(byte[] encryptedKey, byte[] iv, byte[] ciphertext, byte[] tag) Constructs an encrypted envelope with the specified components. 使用指定组件构造加密信封- Parameters:
encryptedKey- the encrypted data encryption keyiv- the initialization vectorciphertext- the encrypted datatag- the authentication tag (can be null for non-AEAD algorithms)- Throws:
NullPointerException- if encryptedKey, iv, or ciphertext is null
-
-
Method Details
-
encryptedKey
public byte[] encryptedKey()Returns the encrypted data encryption key. 返回加密的数据加密密钥- Returns:
- copy of the encrypted key
-
iv
public byte[] iv()Returns the initialization vector. 返回初始化向量- Returns:
- copy of the IV
-
ciphertext
public byte[] ciphertext()Returns the ciphertext. 返回密文- Returns:
- copy of the ciphertext
-
tag
public byte[] tag()Returns the authentication tag. 返回认证标签- Returns:
- copy of the tag, or null if not present
-
toBase64
Serializes this envelope to a Base64 encoded string. 将此信封序列化为 Base64 编码字符串Format: Base64(bytes format)
- Returns:
- Base64 encoded envelope
-
fromBase64
Deserializes an encrypted envelope from a Base64 encoded string. 从 Base64 编码字符串反序列化加密信封- Parameters:
base64- the Base64 encoded envelope- Returns:
- the deserialized envelope
- Throws:
NullPointerException- if base64 is nullOpenCryptoException- if deserialization fails
-
toBytes
public byte[] toBytes()Serializes this envelope to a byte array. 将此信封序列化为字节数组Format: [4-byte encryptedKey length][encryptedKey][4-byte iv length][iv] [4-byte ciphertext length][ciphertext][4-byte tag length][tag or empty]
- Returns:
- serialized envelope bytes
-
fromBytes
Deserializes an encrypted envelope from a byte array. 从字节数组反序列化加密信封- Parameters:
bytes- the serialized envelope bytes- Returns:
- the deserialized envelope
- Throws:
NullPointerException- if bytes is nullOpenCryptoException- if deserialization fails
-
equals
-
hashCode
-
toString
-