Class MessageEncoder
- MessageEncoder
Encrypts / encodes messages between two NEM parties;
tryDecodetries AES-GCM ([tag(16) | iv(12) | cipherText]) then falls back to deprecated AES-CBC ([salt(32) | iv(16) | cipherText], the salt randomising the deprecated shared-key derivation).
-
Constructor Summary
ConstructorsConstructorDescriptionMessageEncoder(KeyPair keyPair) Creates a message encoder around a key pair. -
Method Summary
Modifier and TypeMethodDescriptionencode(CryptoTypes.PublicKey recipientPublicKey, byte[] message) Encodes a message to a recipient using the recommended format.encodeDeprecated(CryptoTypes.PublicKey recipientPublicKey, byte[] message) Encodes a message using the deprecated AES-CBC format; only for compatibility with older NEM messages — new code should useencode(CryptoTypes.PublicKey, byte[]).Returns the public key used for message encoding.tryDecode(CryptoTypes.PublicKey recipientPublicKey, Message encodedMessage) Tries to decode an encoded message.
-
Constructor Details
-
MessageEncoder
Creates a message encoder around a key pair.- Parameters:
keyPair- Key pair.
-
-
Method Details
-
getPublicKey
- MessageEncoder.publicKey
Returns the public key used for message encoding.
- Returns:
Public key used for message encoding.
-
tryDecode
public MessageEncoderResult tryDecode(CryptoTypes.PublicKey recipientPublicKey, Message encodedMessage) - MessageEncoder.tryDecode
Tries to decode an encoded message.
- Parameters:
recipientPublicKey- Recipient public key.encodedMessage- Encoded message.- Returns:
Decoded result; falls back to the original message when both GCM and CBC fail.
- Throws:
IllegalArgumentException- WhenencodedMessage.messageTypeis notMessageType.ENCRYPTED, or when a non-GCM payload is shorter than the CBC salt.
-
encode
- MessageEncoder.encode
Encodes a message to a recipient using the recommended format.
- Parameters:
recipientPublicKey- Recipient public key.message- Message to encode.- Returns:
Encrypted and encoded message.
-
encodeDeprecated
- MessageEncoder.encodeDeprecated
Encodes a message using the deprecated AES-CBC format; only for compatibility with older NEM messages — new code should use
encode(CryptoTypes.PublicKey, byte[]).
- Parameters:
recipientPublicKey- Recipient public key.message- Message to encode.- Returns:
Encrypted and encoded message.
-