@Test public void testWithKeysGeneratedByRecipientKeyGen() throws Exception { ECParameterSpec spec = EllipticCurves.getNistP256Params(); KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC"); keyGen.initialize(spec); String senderId = "foo"; String recipientId = "bar"; KeyPair senderKey = keyGen.generateKeyPair(); ECPublicKey senderPublicKey = (ECPublicKey) senderKey.getPublic(); ECPrivateKey senderPrivateKey = (ECPrivateKey) senderKey.getPrivate(); String recipientPrivateKey = "MEECAQAwEwYHKoZIzj0CAQYIKoZIzj0DAQcEJzAlAgEBBCAP5/1502pXYdMion22yiWK" + "GoTBJN/wAAfdjBU6puyEMw=="; String recipientPublicKey = "BJ995jnw2Ppn4BMP/ZKtlTOOIBQC+/L3PDcFRjowZuCkRqUZ/kGWE8c+zimZNHOZPzLB" + "NVGJ3V8M/fM4g4o02Mc="; PaymentMethodTokenSender sender = new PaymentMethodTokenSender.Builder() .senderId(senderId) .senderSigningKey(senderPrivateKey) .recipientId(recipientId) .rawUncompressedRecipientPublicKey(recipientPublicKey) .build(); PaymentMethodTokenRecipient recipient = new PaymentMethodTokenRecipient.Builder() .senderId(senderId) .addSenderVerifyingKey(senderPublicKey) .recipientId(recipientId) .addRecipientPrivateKey(recipientPrivateKey) .build(); String plaintext = "blah"; assertEquals(plaintext, recipient.unseal(sender.seal(plaintext))); }
public String seal(final String message) throws GeneralSecurityException { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1) || protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2) || protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return sealV1OrV2(message); } throw new GeneralSecurityException("Unsupported version: " + protocolVersion); }
PaymentMethodTokenSender { public String seal(final String message) throws GeneralSecurityException { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1) || protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2) || protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return sealV1OrV2(message); } throw new GeneralSecurityException("Unsupported version: " + protocolVersion); } }
PaymentMethodTokenSender { public String seal(final String message) throws GeneralSecurityException { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1) || protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2) || protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return sealV1OrV2(message); } throw new GeneralSecurityException("Unsupported version: " + protocolVersion); } PaymentMethodTokenSender(Builder builder); }
PaymentMethodTokenSender { public String seal(final String message) throws GeneralSecurityException { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1) || protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2) || protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return sealV1OrV2(message); } throw new GeneralSecurityException("Unsupported version: " + protocolVersion); } PaymentMethodTokenSender(Builder builder); String seal(final String message); }
PaymentMethodTokenSender { public String seal(final String message) throws GeneralSecurityException { if (protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V1) || protocolVersion.equals(PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2) || protocolVersion.equals( PaymentMethodTokenConstants.PROTOCOL_VERSION_EC_V2_SIGNING_ONLY)) { return sealV1OrV2(message); } throw new GeneralSecurityException("Unsupported version: " + protocolVersion); } PaymentMethodTokenSender(Builder builder); String seal(final String message);  }