### Question:
Message { public static byte[] encrypt(byte[] decrypted, SecretKeySpec aes) throws InvalidKeyException, IllegalArgumentException { final ByteBuffer output = ByteBuffer.allocate(NONCE_SIZE + decrypted.length + OVERHEAD); final Cipher cipher; try { cipher = Cipher.getInstance(CIPHER); } catch (NoSuchAlgorithmException | NoSuchPaddingException error) { throw new IllegalArgumentException(error.getMessage()); } final byte[] nonce = new byte[NONCE_SIZE]; random.nextBytes(nonce); final GCMParameterSpec gcm = new GCMParameterSpec(TAG_BITS, nonce); try { cipher.init(Cipher.ENCRYPT_MODE, aes, gcm); } catch (InvalidKeyException error) { if (aes.getAlgorithm() == ALGORITHM && aes.getEncoded().length > 16) { throw new InvalidKeyException(error.getMessage() + ": does your JVM allow keys larger than 128-bit?"); } throw error; } catch (InvalidAlgorithmParameterException error) { throw new IllegalArgumentException(error.getMessage()); } output.put(nonce); try { output.put(cipher.doFinal(decrypted)); } catch(IllegalBlockSizeException | BadPaddingException error) { throw new IllegalArgumentException(error.getMessage()); } return output.array(); }  static byte[] encrypt(byte[] decrypted, SecretKeySpec aes); static byte[] encrypt(String decrypted, SecretKeySpec aes); static byte[] encrypt(byte[] decrypted, byte[] aesBytes); static byte[] encrypt(String decrypted, byte[] aesBytes); static byte[] decrypt(byte []encrypted, SecretKeySpec aes); static byte[] decrypt(String encrypted, SecretKeySpec aes); static byte[] decrypt(byte []encrypted, byte[] aesBytes); static byte[] decrypt(String encrypted, byte[] aesBytes); static String ALGORITHM; static String CIPHER; static int NONCE_SIZE; static int TAG_BITS; static int OVERHEAD; }### Answer:
@Test public void encryptingAMessage() throws Exception { System.out.println("MessageTest.encrypting a message: " + vector); final byte[] want = Helper.combine(vector.getBytes("nonce"), vector.getBytes("ciphertext")); final byte[] test = Message.encrypt(vector.getBytes("plaintext"), vector.getBytes("key")); System.out.println("decrypted:"); Hex.dump(vector.getBytes("plaintext")); System.out.println("encrypted:"); Hex.dump(test); assertThat("encrypt returns byte[]", test instanceof byte[], is(true)); assertThat("encrypted length is " + want.length, test.length, is(want.length)); }