Android payment problem
In Android Pay, the process of creating a credit card token is as follows:
Generate public and private keys (the calls below return the keys using an elliptic curve with the 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'm not sure what the key format / encoding is. I could not find any documentation on this.
Question 1: The correct way to create a public and private key for Android Pay?
Pass the public key in base64 encoded format to the Android Pay createMaskedWalletRequet (for details, see 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 checking MaskedWalletRequest.paymentMethodTokenizationParameters: first byte The parameter "publicKey" must be 0x04 (which indicates an uncompressed format point)
Question 2: Could you help me understand what I am doing wrong. I think this may be due to format mismatch, but not sure and not sure how to fix it.
Appreciate your help!
source share