Package com.gherynos.libsaltpack
Class MessageWriter
java.lang.Object
com.gherynos.libsaltpack.MessageWriter
The class used to encrypt or sign a message.
-
Constructor Summary
ConstructorsConstructorDescriptionMessageWriter
(OutputParameters op, byte[][] recipients) Creates a new MessageWriter instance to encrypt a message remaining anonymous.MessageWriter
(OutputParameters op, byte[][] recipients, boolean visibleRecipients) Creates a new MessageWriter instance to encrypt a message remaining anonymous.MessageWriter
(OutputParameters op, byte[][] recipientsPublickeys, byte[][][] symmetricKeys) Creates a new MessageWriter instance to signcrypt a message remaining anonymous.MessageWriter
(OutputParameters op, byte[] senderSecretkey, boolean detatchedSignature) Creates a new MessageWriter instance to sign a message.MessageWriter
(OutputParameters op, byte[] senderSecretkey, byte[][] recipients) Creates a new MessageWriter instance to encrypt a message.MessageWriter
(OutputParameters op, byte[] senderSecretkey, byte[][] recipients, boolean visibleRecipients) Creates a new MessageWriter instance to encrypt a message.MessageWriter
(OutputParameters op, byte[] senderSecretkey, byte[][] recipientsPublickeys, byte[][][] symmetricKeys) Creates a new MessageWriter instance to signcrypt a message. -
Method Summary
-
Constructor Details
-
MessageWriter
public MessageWriter(OutputParameters op, byte[] senderSecretkey, byte[][] recipients, boolean visibleRecipients) throws SaltpackException Creates a new MessageWriter instance to encrypt a message.- Parameters:
op
- the OutputParameters with the destination output stream that will contain the encrypted data.senderSecretkey
- the private key of the sender, generated byUtils.generateKeypair(byte[] publickey, byte[] secretkey)
.recipients
- the list of public keys of the recipients.visibleRecipients
- if true, the public keys of the recipients will be visible in the encrypted message.- Throws:
SaltpackException
-
MessageWriter
public MessageWriter(OutputParameters op, byte[] senderSecretkey, byte[][] recipients) throws SaltpackException Creates a new MessageWriter instance to encrypt a message. The recipients public keys will be visible in the encrypted message.- Parameters:
op
- the OutputParameters with the destination output stream that will contain the encrypted data.senderSecretkey
- the private key of the sender, generated byUtils.generateKeypair(byte[] publickey, byte[] secretkey)
.recipients
- the list of public keys of the recipients.- Throws:
SaltpackException
-
MessageWriter
public MessageWriter(OutputParameters op, byte[][] recipients, boolean visibleRecipients) throws SaltpackException Creates a new MessageWriter instance to encrypt a message remaining anonymous.- Parameters:
op
- the OutputParameters with the destination output stream that will contain the encrypted data.recipients
- the list of public keys of the recipients.visibleRecipients
- if true, the public keys of the recipients will be visible in the encrypted message.- Throws:
SaltpackException
-
MessageWriter
Creates a new MessageWriter instance to encrypt a message remaining anonymous. The recipients public keys will be visible in the encrypted message.- Parameters:
op
- the OutputParameters with the destination output stream that will contain the encrypted data.recipients
- the list of public keys of the recipients.- Throws:
SaltpackException
-
MessageWriter
public MessageWriter(OutputParameters op, byte[] senderSecretkey, boolean detatchedSignature) throws SaltpackException Creates a new MessageWriter instance to sign a message.- Parameters:
op
- the OutputParameters with the destination output stream that will contain the signed data.senderSecretkey
- the private key of the sender, generated byUtils.generateSignKeypair(byte[] publickey, byte[] secretkey)
.detatchedSignature
- attached/detached signature flag.- Throws:
SaltpackException
-
MessageWriter
public MessageWriter(OutputParameters op, byte[] senderSecretkey, byte[][] recipientsPublickeys, byte[][][] symmetricKeys) throws SaltpackException Creates a new MessageWriter instance to signcrypt a message.- Parameters:
op
- the OutputParameters with the destination output stream that will contain the signcrypted data.senderSecretkey
- the private key of the sender, generated byUtils.generateSignKeypair(byte[] publickey, byte[] secretkey)
.recipientsPublickeys
- the list of Curve25519 public keys of the recipients. The list can be empty.symmetricKeys
- the list of symmetric keys of the recipients: the first array is treated as the identifier, the second as the key itself. The list can be empty.- Throws:
SaltpackException
-
MessageWriter
public MessageWriter(OutputParameters op, byte[][] recipientsPublickeys, byte[][][] symmetricKeys) throws SaltpackException Creates a new MessageWriter instance to signcrypt a message remaining anonymous.- Parameters:
op
- the OutputParameters with the destination output stream that will contain the signcrypted data.recipientsPublickeys
- the list of Curve25519 public keys of the recipients. The list can be empty.symmetricKeys
- the list of symmetric keys of the recipients: the first array is treated as the identifier, the second as the key itself. The list can be empty.- Throws:
SaltpackException
-
-
Method Details
-
destroy
public void destroy()Desctructor.Securely deletes the allocated buffers using `sodium_memzero`.
This method has to be called when the instance is no longer required.
-
addBlock
Adds a block to the current message.- Parameters:
data
- the data for the block, maximum 1MB.isFinal
- the flag defining the last packet of the message.- Throws:
SaltpackException
-
addBlock
Adds a block to the current message.- Parameters:
data
- the data for the block, maximum 1MB.off
- the start offset in the data.len
- the number of bytes to write.isFinal
- the flag defining the last packet of the message.- Throws:
SaltpackException
-