Package anbxj
Class AnBx_WireFormats.SealedMessage
java.lang.Object
anbxj.AnBx_WireFormats.SealedMessage
- All Implemented Interfaces:
Serializable
- Enclosing class:
AnBx_WireFormats
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 Summary
ConstructorsConstructorDescriptionSealedMessage(byte[] encryptedKey, byte[] sealedPayload, String cipherScheme) Constructs a newSealedMessagewrapper. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the cipher scheme used for encryption.byte[]Returns a copy of the encrypted key bytes, ornullif no key was transported.byte[]Returns a copy of the sealed (encrypted) message bytes.inthashCode()parseFrom(byte[] data) Reconstructs aSealedMessagefrom the bytes produced bytoByteArray().byte[]Serialises this sealed message to a deterministic byte format.
-
Constructor Details
-
SealedMessage
Constructs a newSealedMessagewrapper.- Parameters:
encryptedKey- the encrypted symmetric key (may be empty ornullif no key transport is used)sealedPayload- the encrypted message bytes (must not benull)cipherScheme- the cipher scheme string (e.g."AES/GCM/NoPadding")- Throws:
NullPointerException- ifsealedPayloadorcipherSchemeisnull
-
-
Method Details
-
getEncryptedKey
public byte[] getEncryptedKey()Returns a copy of the encrypted key bytes, ornullif 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
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:
- 4-byte big-endian length of the encrypted key (0 if
null) - encrypted key bytes (omitted if length is 0)
- 4-byte big-endian length of the encrypted message payload
- encrypted message payload bytes
- 2-byte big-endian length of the cipher scheme string (UTF-8)
- cipher scheme bytes
- Returns:
- the serialised bytes (never
null) - Throws:
UncheckedIOException- if an I/O error occurs (should not happen with in-memory streams)
- 4-byte big-endian length of the encrypted key (0 if
-
parseFrom
Reconstructs aSealedMessagefrom the bytes produced bytoByteArray().The expected format is described in
toByteArray(). A leading encrypted-key length of0results in anullkey.- Parameters:
data- the serialised bytes (must not benull)- Returns:
- the reconstructed sealed message
- Throws:
IOException- if the bytes are malformed or truncated
-
equals
-
hashCode
public int hashCode()
-