@Test
public void testShouldFailIfSignedECV1WithKeyForWrongProtocolVersion() throws Exception {

  JSONObject trustedKeysJson = new JSONObject(GOOGLE_VERIFYING_PUBLIC_KEYS_JSON);
  JSONArray keys = trustedKeysJson.getJSONArray("keys");
  JSONObject correctKeyButWrongProtocol =
      new JSONObject(keys.getJSONObject(INDEX_OF_GOOGLE_SIGNING_EC_V1).toString())
          .put(PaymentMethodTokenConstants.JSON_PROTOCOL_VERSION_KEY, "ECv2");
  JSONObject wrongKeyButRightProtocol =
      new JSONObject(keys.getJSONObject(INDEX_OF_GOOGLE_SIGNING_EC_V1).toString())
          .put("keyValue", ALTERNATE_PUBLIC_SIGNING_KEY)
          .put(
              PaymentMethodTokenConstants.JSON_PROTOCOL_VERSION_KEY,
              PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1);
  trustedKeysJson.put(
      "keys", new JSONArray().put(correctKeyButWrongProtocol).put(wrongKeyButRightProtocol));
  PaymentMethodTokenRecipient recipient =
      new PaymentMethodTokenRecipient.Builder()
          .senderVerifyingKeys(trustedKeysJson.toString())
          .recipientId(RECIPIENT_ID)
          .addRecipientPrivateKey(MERCHANT_PRIVATE_KEY_PKCS8_BASE64)
          .build();
  try {
    recipient.unseal(CIPHERTEXT_EC_V1);
    fail("Expected GeneralSecurityException");
  } catch (GeneralSecurityException e) {
    assertEquals("cannot verify signature", e.getMessage());
  }
}