CryptoUtils { public static byte[] encryptToAesGcm(final byte[] message, final byte[] password, final byte[] nonce) throws IllegalStateException, InvalidCipherTextException { final GCMBlockCipher cipher = new GCMBlockCipher(new AESEngine()); CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(password), nonce); cipher.init(true, ivAndKey); final byte[] outBuf = new byte[cipher.getOutputSize(message.length)]; int outOff = cipher.processBytes(message, 0, message.length, outBuf, 0); cipher.doFinal(outBuf, outOff); return outBuf; }  static SecretKeySpec createSecret(final byte[] password, final int length); static String encryptToAes128EcbWithBase64(final String source); static String encryptToAes128EcbWithBase64(final String source, final String password); static String encryptToAes128EcbWithBase64(final byte[] message,
      final SecretKeySpec secretKeySpec); static byte[] encryptToAesGcm(final byte[] message, final byte[] password,
      final byte[] nonce); static byte[] decryptFromAes128EcbWithBase64(final String source); static byte[] decryptFromAes128EcbWithBase64(final String source, final String password); static byte[] decryptFromAes128EcbWithBase64(final String source,
      final SecretKeySpec secretKeySpec); static byte[] decryptFromAesGcm(final byte[] source, final byte[] password,
      final byte[] nonce); static final String CIPHER_CHARSET; static final String CIPHER_NAME; }
@Test public void testEncryptToAes256Gcm() throws Exception { final Random random = new Random(); for (int i = 0; i < 100; ++i) { byte[] message = randomUUID().toString().getBytes(); byte[] nonce = Arrays.copyOfRange(randomUUID().toString().getBytes(), 0, 14); byte[] password = new byte[32]; random.nextBytes(password); assertNotNull(CryptoUtils.encryptToAesGcm(message, password, nonce)); } }