@Test public void testVectorDecrypt() throws GeneralSecurityException { int i = 0; for (TestVector testVector : testVectors) { int bufferSize = testVector.ciphertext.length; byte[] plaintext = new byte[bufferSize]; ByteBuffer plaintextBuffer = ByteBuffer.wrap(plaintext); AesGcmHkdfAeadCrypter aeadCrypter = new AesGcmHkdfAeadCrypter(testVector.key); aeadCrypter.decrypt( plaintextBuffer, ByteBuffer.wrap(testVector.ciphertext), ByteBuffer.wrap(testVector.aad), testVector.nonce); String msg = "Failure for test vector " + i; assertWithMessage(msg) .that(plaintextBuffer.remaining()) .isEqualTo(bufferSize - testVector.plaintext.length); byte[] exactPlaintext = Arrays.copyOf(plaintext, testVector.plaintext.length); assertWithMessage(msg).that(exactPlaintext).isEqualTo(testVector.plaintext); i++; } }
@Override public void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, byte[] nonce) throws GeneralSecurityException { maybeRekey(nonce); maskNonce(nonceBuffer, nonceMask, nonce); aeadCrypter.decrypt(plaintext, ciphertext, nonceBuffer); }
AesGcmHkdfAeadCrypter implements AeadCrypter { @Override public void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, byte[] nonce) throws GeneralSecurityException { maybeRekey(nonce); maskNonce(nonceBuffer, nonceMask, nonce); aeadCrypter.decrypt(plaintext, ciphertext, nonceBuffer); } }
AesGcmHkdfAeadCrypter implements AeadCrypter { @Override public void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, byte[] nonce) throws GeneralSecurityException { maybeRekey(nonce); maskNonce(nonceBuffer, nonceMask, nonce); aeadCrypter.decrypt(plaintext, ciphertext, nonceBuffer); } AesGcmHkdfAeadCrypter(byte[] key); }
AesGcmHkdfAeadCrypter implements AeadCrypter { @Override public void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, byte[] nonce) throws GeneralSecurityException { maybeRekey(nonce); maskNonce(nonceBuffer, nonceMask, nonce); aeadCrypter.decrypt(plaintext, ciphertext, nonceBuffer); } AesGcmHkdfAeadCrypter(byte[] key); @Override void encrypt(ByteBuffer ciphertext, ByteBuffer plaintext, byte[] nonce); @Override void encrypt(ByteBuffer ciphertext, ByteBuffer plaintext, ByteBuffer aad, byte[] nonce); @Override void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, byte[] nonce); @Override void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, ByteBuffer aad, byte[] nonce); }
AesGcmHkdfAeadCrypter implements AeadCrypter { @Override public void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, byte[] nonce) throws GeneralSecurityException { maybeRekey(nonce); maskNonce(nonceBuffer, nonceMask, nonce); aeadCrypter.decrypt(plaintext, ciphertext, nonceBuffer); } AesGcmHkdfAeadCrypter(byte[] key); @Override void encrypt(ByteBuffer ciphertext, ByteBuffer plaintext, byte[] nonce); @Override void encrypt(ByteBuffer ciphertext, ByteBuffer plaintext, ByteBuffer aad, byte[] nonce); @Override void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, byte[] nonce); @Override void decrypt(ByteBuffer plaintext, ByteBuffer ciphertext, ByteBuffer aad, byte[] nonce);  }