@Test public void testShouldTryAllKeysToDecryptECV1() throws Exception { PaymentMethodTokenRecipient recipient = new PaymentMethodTokenRecipient.Builder() .senderVerifyingKeys(GOOGLE_VERIFYING_PUBLIC_KEYS_JSON) .recipientId(RECIPIENT_ID) .addRecipientPrivateKey(ALTERNATE_MERCHANT_PRIVATE_KEY_PKCS8_BASE64) .addRecipientPrivateKey(MERCHANT_PRIVATE_KEY_PKCS8_BASE64) .build(); assertEquals(PLAINTEXT, recipient.unseal(CIPHERTEXT_EC_V1)); }
public String unseal(final String sealedMessage) throws GeneralSecurityException { try { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1)) { return unsealECV1(sealedMessage); } else if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)) { return unsealECV2(sealedMessage); } else if (protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return unsealECV2SigningOnly(sealedMessage); } throw new IllegalArgumentException("unsupported version: " + protocolVersion); } catch (JSONException e) { throw new GeneralSecurityException("cannot unseal; invalid JSON message"); } }
PaymentMethodTokenRecipient { public String unseal(final String sealedMessage) throws GeneralSecurityException { try { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1)) { return unsealECV1(sealedMessage); } else if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)) { return unsealECV2(sealedMessage); } else if (protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return unsealECV2SigningOnly(sealedMessage); } throw new IllegalArgumentException("unsupported version: " + protocolVersion); } catch (JSONException e) { throw new GeneralSecurityException("cannot unseal; invalid JSON message"); } } }
PaymentMethodTokenRecipient { public String unseal(final String sealedMessage) throws GeneralSecurityException { try { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1)) { return unsealECV1(sealedMessage); } else if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)) { return unsealECV2(sealedMessage); } else if (protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return unsealECV2SigningOnly(sealedMessage); } throw new IllegalArgumentException("unsupported version: " + protocolVersion); } catch (JSONException e) { throw new GeneralSecurityException("cannot unseal; invalid JSON message"); } } PaymentMethodTokenRecipient(
      String protocolVersion,
      List<SenderVerifyingKeysProvider> senderVerifyingKeysProviders,
      String senderId,
      List<ECPrivateKey> recipientPrivateKeys,
      List<PaymentMethodTokenRecipientKem> recipientKems,
      String recipientId); private  PaymentMethodTokenRecipient(Builder builder); }
PaymentMethodTokenRecipient { public String unseal(final String sealedMessage) throws GeneralSecurityException { try { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1)) { return unsealECV1(sealedMessage); } else if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)) { return unsealECV2(sealedMessage); } else if (protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return unsealECV2SigningOnly(sealedMessage); } throw new IllegalArgumentException("unsupported version: " + protocolVersion); } catch (JSONException e) { throw new GeneralSecurityException("cannot unseal; invalid JSON message"); } } PaymentMethodTokenRecipient(
      String protocolVersion,
      List<SenderVerifyingKeysProvider> senderVerifyingKeysProviders,
      String senderId,
      List<ECPrivateKey> recipientPrivateKeys,
      List<PaymentMethodTokenRecipientKem> recipientKems,
      String recipientId); private  PaymentMethodTokenRecipient(Builder builder); String unseal(final String sealedMessage); }
PaymentMethodTokenRecipient { public String unseal(final String sealedMessage) throws GeneralSecurityException { try { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1)) { return unsealECV1(sealedMessage); } else if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2)) { return unsealECV2(sealedMessage); } else if (protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return unsealECV2SigningOnly(sealedMessage); } throw new IllegalArgumentException("unsupported version: " + protocolVersion); } catch (JSONException e) { throw new GeneralSecurityException("cannot unseal; invalid JSON message"); } } PaymentMethodTokenRecipient(
      String protocolVersion,
      List<SenderVerifyingKeysProvider> senderVerifyingKeysProviders,
      String senderId,
      List<ECPrivateKey> recipientPrivateKeys,
      List<PaymentMethodTokenRecipientKem> recipientKems,
      String recipientId); private  PaymentMethodTokenRecipient(Builder builder); String unseal(final String sealedMessage);  }