Class SimpleBox


  • public class SimpleBox
    extends java.lang.Object
    Convenience functions for encryption without requiring nonce management.

    Compatible with RbNaCl's SimpleBox construction, but generates misuse-resistant nonces.

    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleBox​(byte[] secretKey)
      Create a new SimpleBox instance with the given secret key.
      SimpleBox​(byte[] publicKey, byte[] privateKey)
      Create a new SecretBox instance given a Curve25519 public key and a Curve25519 private key.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Optional<byte[]> open​(byte[] ciphertext)
      Decrypt the ciphertext with the given key.
      byte[] seal​(byte[] plaintext)
      Encrypt the plaintext with the given key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SimpleBox

        public SimpleBox​(byte[] secretKey)
        Create a new SimpleBox instance with the given secret key.
        Parameters:
        secretKey - a 32-byte secret key
      • SimpleBox

        public SimpleBox​(byte[] publicKey,
                         byte[] privateKey)
        Create a new SecretBox instance given a Curve25519 public key and a Curve25519 private key.
        Parameters:
        publicKey - a Curve25519 public key
        privateKey - a Curve25519 private key
    • Method Detail

      • seal

        public byte[] seal​(byte[] plaintext)
        Encrypt the plaintext with the given key.
        Parameters:
        plaintext - any arbitrary bytes
        Returns:
        the ciphertext
      • open

        public java.util.Optional<byte[]> open​(byte[] ciphertext)
        Decrypt the ciphertext with the given key.
        Parameters:
        ciphertext - an encrypted message
        Returns:
        an Optional of the original plaintext, or if either the key, nonce, or ciphertext was modified, an empty Optional