@Test
  public void testEncryptDecryptKeysDiffIvSize() throws Exception {
    int[] ivSizes = {12, 16, 24, 32, 48, 64};
    for (int ivSize : ivSizes) {
      String keyToEncrypt = TestUtils.getRandomKey(DEFAULT_KEY_SIZE_IN_CHARS);
      Properties props = getKMSProperties(keyToEncrypt, DEFAULT_KEY_SIZE_IN_CHARS);
      props.setProperty("crypto.service.iv.size.in.bytes", Integer.toString(ivSize));
      VerifiableProperties verifiableProperties = new VerifiableProperties((props));
      SecretKeySpec secretKeyToEncrypt = new SecretKeySpec(Hex.decode(keyToEncrypt), "AES");
      String keyToBeEncrypted = TestUtils.getRandomKey(DEFAULT_KEY_SIZE_IN_CHARS);
      SecretKeySpec secretKeyToBeEncrypted = new SecretKeySpec(Hex.decode(keyToBeEncrypted), "AES");
      CryptoService<SecretKeySpec> cryptoService =
          new GCMCryptoServiceFactory(verifiableProperties, REGISTRY).getCryptoService();
      ByteBuffer encryptedBytes = cryptoService.encryptKey(secretKeyToBeEncrypted, secretKeyToEncrypt);
      Assert.assertFalse("Encrypted key and plain key should not match",
          Arrays.equals(keyToBeEncrypted.getBytes(), encryptedBytes.array()));
      SecretKeySpec decryptedKey = cryptoService.decryptKey(encryptedBytes, secretKeyToEncrypt);
      Assert.assertEquals("Decrypted Key and original key mismatch", secretKeyToBeEncrypted, decryptedKey);
    }
  }
Tests encryption and decryption of keys with diff iv sizes
ambry-router/src/test/java/com/github/ambry/router/GCMCryptoServiceTest.java