ChaCha20Poly1305Cipher implements EncryptionCipher, DecryptionCipher { @Override public byte[] decrypt(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 testDecrypt() { byte[] iv = ArrayConverter.hexStringToByteArray("FC8A9AA4809FB4F11B5E6E2B"); byte[] key = ArrayConverter .hexStringToByteArray("7A3B05D1E2A054BB00ED2E308463D4AA258C1E54F946898919B059765B8636DD"); byte[] aad = ArrayConverter.hexStringToByteArray("00000000000000001603030010"); byte[] ciphertext = ArrayConverter .hexStringToByteArray("C11D4D4DE0E1B97DFA9BB935A7E072B27EB0FD0483F8586842155D48CBC552FD"); byte[] expectedPlaintext = ArrayConverter.hexStringToByteArray("1400000C5C2BB43710C69470E41B058C"); ChaCha20Poly1305Cipher decryptCipher = new ChaCha20Poly1305Cipher(key); byte[] calculatedPlaintext = decryptCipher.decrypt(iv, 16 * 8, aad, ciphertext); Assert.assertArrayEquals(expectedPlaintext, calculatedPlaintext); }