@Test
  public void testEncryptDecryptBytes() throws Exception {
    for (int j = 0; j < 3; j++) {
      String key = TestUtils.getRandomKey(DEFAULT_KEY_SIZE_IN_CHARS);
      Properties props = getKMSProperties(key, DEFAULT_KEY_SIZE_IN_CHARS);
      VerifiableProperties verifiableProperties = new VerifiableProperties((props));
      SecretKeySpec secretKeySpec = new SecretKeySpec(Hex.decode(key), "AES");
      CryptoService<SecretKeySpec> cryptoService =
          new GCMCryptoServiceFactory(verifiableProperties, REGISTRY).getCryptoService();
      for (int i = 0; i < 5; i++) {
        int size = TestUtils.RANDOM.nextInt(MAX_DATA_SIZE);
        byte[] randomData = new byte[size];
        TestUtils.RANDOM.nextBytes(randomData);
        ByteBuffer toEncrypt = ByteBuffer.wrap(randomData);
        ByteBuffer encryptedBytes = cryptoService.encrypt(toEncrypt, secretKeySpec);
        Assert.assertFalse("Encrypted bytes and plain bytes should not match",
            Arrays.equals(randomData, encryptedBytes.array()));
        ByteBuffer decryptedBytes = cryptoService.decrypt(encryptedBytes, secretKeySpec);
        Assert.assertArrayEquals("Decrypted bytes and plain bytes should match", randomData, decryptedBytes.array());
      }
    }
  }
Tests basic encryption and decryption for different sizes of keys and random data in bytes
ambry-router/src/test/java/com/github/ambry/router/GCMCryptoServiceTest.java