ChaCha20Poly1305Cipher implements EncryptionCipher, DecryptionCipher { @Override public byte[] encrypt(byte[] someBytes) throws CryptoException { throw new UnsupportedOperationException("ChaCha20Poly1305 can only be used as an AEAD Cipher!"); } ChaCha20Poly1305Cipher(byte[] key); @Override byte[] decrypt(byte[] someBytes); @Override byte[] decrypt(byte[] iv, byte[] someBytes); @Override byte[] decrypt(byte[] iv, int tagLength, byte[] someBytes); @Override byte[] decrypt(byte[] iv, int tagLength, byte[] additionalAuthenticatedData, byte[] ciphertext); @Override byte[] encrypt(byte[] someBytes); @Override byte[] encrypt(byte[] iv, byte[] someBytes); @Override byte[] encrypt(byte[] iv, int tagLength, byte[] someBytes); @Override byte[] encrypt(byte[] iv, int tagLength, byte[] additionAuthenticatedData, byte[] someBytes); @Override int getBlocksize(); @Override byte[] getIv(); @Override void setIv(byte[] iv);  }
@Test public void testEncrypt() { byte[] iv = ArrayConverter.hexStringToByteArray("DB9225611E4646D7D10BA135"); byte[] key = ArrayConverter .hexStringToByteArray("5C602601DBAC4CD0B8BA794A208763A8036C239C91835BA8FD4396B34F004F3A"); byte[] aad = ArrayConverter.hexStringToByteArray("00000000000000001603030010"); byte[] plaintext = ArrayConverter.hexStringToByteArray("1400000C910399922449024F3C8006EF"); byte[] expectedCiphertext = ArrayConverter .hexStringToByteArray("ACE73C8630758D6DBFCEF6D1A0318D4F85BA532C183455F27E00618365DE1A57"); ChaCha20Poly1305Cipher encryptCipher = new ChaCha20Poly1305Cipher(key); byte[] calculatedCiphertext = encryptCipher.encrypt(iv, 16 * 8, aad, plaintext); Assert.assertArrayEquals(expectedCiphertext, calculatedCiphertext); }