@Test
public void testInvalidKeyMaterial() throws Exception {

  Key valid =
      TestUtil.createKey(
          TestUtil.createAesGcmHkdfStreamingKeyData(
              Random.randBytes(KDF_KEY_SIZE), AES_KEY_SIZE, 128),
          42,
          KeyStatusType.ENABLED,
          OutputPrefixType.RAW);
  Key invalid =
      TestUtil.createKey(
          TestUtil.createAesSivKeyData(64), 43, KeyStatusType.ENABLED, OutputPrefixType.TINK);
  KeysetHandle keysetHandle = TestUtil.createKeysetHandle(TestUtil.createKeyset(valid, invalid));
  try {
    StreamingAeadFactory.getPrimitive(keysetHandle);
    fail("Expected GeneralSecurityException");
  } catch (GeneralSecurityException e) {
    assertExceptionContains(e, "com.google.crypto.tink.StreamingAead not supported");
  }
  // invalid as the primary key.
  keysetHandle = TestUtil.createKeysetHandle(TestUtil.createKeyset(invalid, valid));
  try {
    StreamingAeadFactory.getPrimitive(keysetHandle);
    fail("Expected GeneralSecurityException");
  } catch (GeneralSecurityException e) {
    assertExceptionContains(e, "com.google.crypto.tink.StreamingAead not supported");
  }
}