### Question:
Stream { static public InputStream decrypt(InputStream stream, SecretKeySpec aes) throws IOException, InvalidKeyException { try { byte[] nonce = new byte[Message.NONCE_SIZE]; stream.read(nonce); GCMParameterSpec gcm = new GCMParameterSpec(Message.TAG_BITS, nonce); Cipher aesgcm = Cipher.getInstance("AES/GCM/NoPadding"); aesgcm.init(Cipher.DECRYPT_MODE, aes, gcm); byte[] encryptedIVAndTag = new byte[IV_SIZE + (Message.TAG_BITS >> 3)]; stream.read(encryptedIVAndTag); byte[] iv = aesgcm.doFinal(encryptedIVAndTag); IvParameterSpec ctr = new IvParameterSpec(iv); Cipher aesctr = Cipher.getInstance("AES/CTR/NoPadding"); aesctr.init(Cipher.DECRYPT_MODE, aes, ctr); return new CipherInputStream(stream, aesctr); } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchPaddingException | IllegalBlockSizeException | BadPaddingException error) { throw new RuntimeException(error); } }  static byte[] exchange(InputStream is, OutputStream os); static OutputStream encrypt(OutputStream stream, SecretKeySpec aes); static OutputStream encrypt(OutputStream stream, byte[] aesBytes); static InputStream decrypt(InputStream stream, SecretKeySpec aes); static InputStream decrypt(InputStream stream, byte[] aesBytes); static public String ALGORITHM; }### Answer:
@Test public void decryptStream() throws Exception { System.out.println("StreamTest.decryptStream " + vector); byte[] key = vector.getBytes("key"); byte[] input = vector.getBytes("encrypted"); byte[] want = vector.getBytes("decrypted"); byte[] test = new byte[want.length]; ByteArrayInputStream bis = new ByteArrayInputStream(input); InputStream stream = Stream.decrypt(bis, key); stream.read(test); stream.close(); System.out.println("encrypted:"); Hex.dump(input); System.out.println("decrypted:"); Hex.dump(test); assertThat("message decrypted correctly", test, is(want)); }