Class MessageReader

java.lang.Object
com.gherynos.libsaltpack.MessageReader

public class MessageReader extends Object
The class used to decrypt or verify a message.
  • Constructor Details

    • MessageReader

      public MessageReader(InputParameters in, byte[] recipientSecretkey) throws SaltpackException
      Creates a new MessageReader instance to decrypt a message.
      Parameters:
      in - the InputParameters with the source input stream containing the encrypted message.
      recipientSecretkey - the private key of the sender.
      Throws:
      SaltpackException
    • MessageReader

      public MessageReader(InputParameters in) throws SaltpackException
      Creates a new MessageReader instance to verify a signed message.
      Parameters:
      in - the InputParameters with the source input stream containing the message with its signature attached.
      Throws:
      SaltpackException
    • MessageReader

      public MessageReader(InputParameters in, InputStream messageIn) throws SaltpackException
      Creates a new MessageReader instance to verify a signed message.
      Parameters:
      in - the InputParameters with the source input stream containing the detached signature.
      messageIn - the input stream containing the message to verify.
      Throws:
      SaltpackException - if the signature verification fails.
    • MessageReader

      public MessageReader(InputParameters in, byte[] recipientSecretkey, byte[][] symmetricKey) throws SaltpackException
      Creates a new MessageReader instance to decrypt and verify a signcrypted message.
      Parameters:
      in - the InputParameters with the source input stream containing the detached signature.
      recipientSecretkey - the Curve25519 private key of the recipient. The array can be empty.
      symmetricKey - the symmetric key of the recipient: the first array is treated as the identifier, the second as the key itself. The arrays can be empty.
      Throws:
      SaltpackException - if the signature verification fails.
  • 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.

    • hasMoreBlocks

      public boolean hasMoreBlocks() throws SaltpackException
      Helper method to process all the blocks.
      Returns:
      true when there are more blocks to read, false otherwise.
      Throws:
      SaltpackException
    • getBlock

      public byte[] getBlock() throws SaltpackException
      Returns the next block of the decrypted/verified message.
      Returns:
      the decrypted/verified data.
      Throws:
      SaltpackException - if the block cannot be decrypted or its signature is not valid.
    • getRecipients

      public byte[][] getRecipients() throws SaltpackException
      Returns the public keys of the recipients if they're visible (see flag visibleRecipients in MessageWriter).
      Returns:
      the recipients if they're visible, an empty array otherwise.
      Throws:
      SaltpackException
    • getSender

      public byte[] getSender() throws SaltpackException
      Returns the public key of the sender.
      Returns:
      the sender's public key.
      Throws:
      SaltpackException
    • isIntentionallyAnonymous

      public boolean isIntentionallyAnonymous() throws SaltpackException
      Sender's anonimity status (see MessageWriter(OutputParameters, byte[][])).
      Returns:
      true if the sender of the message is intentionally anonymous, false otherwise.
      Throws:
      SaltpackException