Android Pay Issue
In Android Pay the process to generate a token from a credit card is as follows:
Generate a public and private key (the calls below return the keys using an Elliptic Curve with NISTP-256 algorithm)
To do this I call ...
public static KeyPair generateKeyPair() {
KeyPair pair =null;
try {
ECGenParameterSpec ecGenSpec = new ECGenParameterSpec("prime256v1");
java.security.KeyPairGenerator g = KeyPairGenerator.getInstance("EC");
g.initialize(ecGenSpec, new SecureRandom());
pair = g.generateKeyPair();
pair.getPrivate();
pair.getPublic();
}catch (Throwable e ){
e.printStackTrace();
}
return pair;
}
… This successfully returns the public and private key, but I am not sure what the format/encoding of the keys is in. I could not find any documentation on this.
Question 1: Is this the right way to generate a public and private key for Android Pay?
Pass the public key in base64 encoded format to the Android Pay createMaskedWalletRequet
method (details of this are in the Android Pay documentation)
String publicKey = String (Base64.encodeBase64(pair.getPublic().getEncoded()));
PaymentMethodTokenizationParameters parameters = PaymentMethodTokenizationParameters.newBuilder().setPaymentMethodTokenizationType(PaymentMethodTokenizationType.NETWORK_TOKEN).addParameter("publicKey", publicKey).build();
Here I get the following exception:
03-30 17:02:06.459 3786-15263/? E/WalletClient: Error validating MaskedWalletRequest.paymentMethodTokenizationParameters: first byte of parameter "publicKey" must be 0x04 (which indicates uncompressed point format)
Question 2: Can you please help me understand what I am doing wrong. I think this may be related to a format mismatch, but not sure, and not sure how to fix it.
Appreciate your help!!