Class EncryptedEnvelope

java.lang.Object
cloud.opencode.base.crypto.envelope.EncryptedEnvelope

public final class EncryptedEnvelope extends Object
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 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 key
      iv - the initialization vector
      ciphertext - the encrypted data
      tag - 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

      public String toBase64()
      Serializes this envelope to a Base64 encoded string. 将此信封序列化为 Base64 编码字符串

      Format: Base64(bytes format)

      Returns:
      Base64 encoded envelope
    • fromBase64

      public static EncryptedEnvelope fromBase64(String base64)
      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 null
      OpenCryptoException - 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

      public static EncryptedEnvelope fromBytes(byte[] bytes)
      Deserializes an encrypted envelope from a byte array. 从字节数组反序列化加密信封
      Parameters:
      bytes - the serialized envelope bytes
      Returns:
      the deserialized envelope
      Throws:
      NullPointerException - if bytes is null
      OpenCryptoException - if deserialization fails
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object