@Test
  public void testBadDecryptInput() throws GeneralSecurityException {
    byte[] garbage = TestUtils.getRandomBytes(10000);
    //zero out version, encrypted key size, encrypted data size fields
    for (int i = 0; i < CloudBlobCryptoAgentImpl.EncryptedDataPayload.INITIAL_MESSAGE_LENGTH; i++) {
      garbage[i] = 0;
    }
    //Version check should fail
    try {
      cryptoAgent.decrypt(ByteBuffer.wrap(garbage)).array();
      fail("Should have thrown exception");
    } catch (GeneralSecurityException e) {
      //expected
    }
    //Version check pass, encrypted key size check should fail
    garbage[1] = 1;
    garbage[2] = -128;
    try {
      cryptoAgent.decrypt(ByteBuffer.wrap(garbage)).array();
      fail("Should have thrown exception");
    } catch (GeneralSecurityException e) {
      //expected
    }
    //Version check, encrypted key size check pass, encrypted data size check fail
    garbage[2] = 0;
    garbage[5] = 79;
    garbage[6] = -128;
    garbage[10] = -128;
    try {
      cryptoAgent.decrypt(ByteBuffer.wrap(garbage)).array();
      fail("Should have thrown exception");
    } catch (GeneralSecurityException e) {
      //expected
    }
    //Version check, encrypted key size check, encrypted data size check pass,
    //crc check fail
    garbage[6] = 0;
    garbage[10] = 0;
    garbage[13] = 79;
    try {
      cryptoAgent.decrypt(ByteBuffer.wrap(garbage)).array();
      fail("Should have thrown exception");
    } catch (GeneralSecurityException e) {
      //expected
    }
  }
Tests that all data validation checks work for decryption
@throws GeneralSecurityException
ambry-cloud/src/test/java/com/github/ambry/cloud/CloudBlobCryptoAgentImplTest.java