Package anbxj

Class AnBx_WireFormats.SealedMessage

java.lang.Object
anbxj.AnBx_WireFormats.SealedMessage
All Implemented Interfaces:
Serializable
Enclosing class:
AnBx_WireFormats

public static final class AnBx_WireFormats.SealedMessage extends Object implements Serializable
A language-agnostic representation of a sealed (encrypted) message.

This wrapper replaces SealedObject and Crypto_SealedPair. It holds the encrypted form of a message and, optionally, an encrypted symmetric key (for hybrid encryption). The cipher scheme string indicates the algorithm, mode and padding used (e.g., "AES/GCM/NoPadding").

For symmetric-only encryption (no key transport), the encryptedKey array may be empty or null. For hybrid encryption, it contains the asymmetric encryption of the symmetric key.

See Also:
  • Constructor Details

    • SealedMessage

      public SealedMessage(byte[] encryptedKey, byte[] sealedPayload, String cipherScheme)
      Constructs a new SealedMessage wrapper.
      Parameters:
      encryptedKey - the encrypted symmetric key (may be empty or null if no key transport is used)
      sealedPayload - the encrypted message bytes (must not be null)
      cipherScheme - the cipher scheme string (e.g. "AES/GCM/NoPadding")
      Throws:
      NullPointerException - if sealedPayload or cipherScheme is null
  • Method Details

    • getEncryptedKey

      public byte[] getEncryptedKey()
      Returns a copy of the encrypted key bytes, or null if no key was transported.
      Returns:
      a fresh copy of the encrypted key array, or null
    • getSealedMessage

      public byte[] getSealedMessage()
      Returns a copy of the sealed (encrypted) message bytes.
      Returns:
      a fresh copy of the sealed message byte array
    • getCipherScheme

      public String getCipherScheme()
      Returns the cipher scheme used for encryption.
      Returns:
      the cipher scheme string (never null)
    • toByteArray

      public byte[] toByteArray()
      Serialises this sealed message to a deterministic byte format.

      The binary layout is:

      1. 4-byte big-endian length of the encrypted key (0 if null)
      2. encrypted key bytes (omitted if length is 0)
      3. 4-byte big-endian length of the encrypted message payload
      4. encrypted message payload bytes
      5. 2-byte big-endian length of the cipher scheme string (UTF-8)
      6. cipher scheme bytes
      This format is language-agnostic and can be parsed by any implementation.
      Returns:
      the serialised bytes (never null)
      Throws:
      UncheckedIOException - if an I/O error occurs (should not happen with in-memory streams)
    • parseFrom

      public static AnBx_WireFormats.SealedMessage parseFrom(byte[] data) throws IOException
      Reconstructs a SealedMessage from the bytes produced by toByteArray().

      The expected format is described in toByteArray(). A leading encrypted-key length of 0 results in a null key.

      Parameters:
      data - the serialised bytes (must not be null)
      Returns:
      the reconstructed sealed message
      Throws:
      IOException - if the bytes are malformed or truncated
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class Object