Class InsecureNonceXChaCha20


  • public class InsecureNonceXChaCha20
    extends java.lang.Object
    InsecureNonceXChaCha20 stream cipher based on https://download.libsodium.org/doc/advanced/xchacha20.html and https://tools.ietf.org/html/draft-arciszewski-xchacha-01.

    This cipher is meant to be used to construct an AEAD with Poly1305. Specifically, it is only intended to be used for scenarios that require user-supplied nonces, which would be insecure if the user-supplied nonce ever repeats. Therefore, most users should prefer XChaCha20 instead, since it automatically supplies random nonce inputs.

    • Constructor Summary

      Constructors 
      Constructor Description
      InsecureNonceXChaCha20​(byte[] key, int initialCounter)
      Constructs a new InsecureNonceXChaCha20 cipher with the supplied key.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] decrypt​(byte[] nonce, byte[] ciphertext)
      Decrypts ciphertext using nonce.
      byte[] decrypt​(byte[] nonce, java.nio.ByteBuffer ciphertext)
      Decrypts ciphertext using nonce.
      byte[] encrypt​(byte[] nonce, byte[] plaintext)
      Encrypts plaintext using nonce.
      void encrypt​(java.nio.ByteBuffer output, byte[] nonce, byte[] plaintext)
      Encrypts plaintext using nonce and writes result to output.
      • Methods inherited from class java.lang.Object

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

      • InsecureNonceXChaCha20

        public InsecureNonceXChaCha20​(byte[] key,
                                      int initialCounter)
                               throws java.security.InvalidKeyException
        Constructs a new InsecureNonceXChaCha20 cipher with the supplied key.
        Throws:
        java.lang.IllegalArgumentException - when key length is not ChaCha20Util.KEY_SIZE_IN_BYTES.
        java.security.InvalidKeyException
    • Method Detail

      • encrypt

        public byte[] encrypt​(byte[] nonce,
                              byte[] plaintext)
                       throws java.security.GeneralSecurityException
        Encrypts plaintext using nonce.
        Throws:
        java.security.GeneralSecurityException
      • encrypt

        public void encrypt​(java.nio.ByteBuffer output,
                            byte[] nonce,
                            byte[] plaintext)
                     throws java.security.GeneralSecurityException
        Encrypts plaintext using nonce and writes result to output.
        Throws:
        java.security.GeneralSecurityException
      • decrypt

        public byte[] decrypt​(byte[] nonce,
                              byte[] ciphertext)
                       throws java.security.GeneralSecurityException
        Decrypts ciphertext using nonce.
        Throws:
        java.security.GeneralSecurityException
      • decrypt

        public byte[] decrypt​(byte[] nonce,
                              java.nio.ByteBuffer ciphertext)
                       throws java.security.GeneralSecurityException
        Decrypts ciphertext using nonce.
        Throws:
        java.security.GeneralSecurityException