chengbo / ApplePayAndroidPayDecryption

A C# library to decrypt Apple Pay or Android Pay token on the server side.
MIT License
11 stars 0 forks source link

System.NullReferenceException PrivateKeyFactory #4

Open FeyverkSoft opened 7 years ago

FeyverkSoft commented 7 years ago

Hi Cheng.

            var p = new ApplePayParameters
            {
                PrivateKey = "MIIEvQIBADANBgkqhkiG9w........=",
                EphemeralPublicKey = "MFkwEwYHKoZI.......==",
                MerchantIdentifier = "me...."
            };
            ApplePayTokenDecrypter d = new ApplePayTokenDecrypter();
            d.Init(p);
           var res = d.Decrypt("Q8JclPEJp....ZGYl","");

The Decryption method throws an exception on the call PrivateKeyParameters = CreatePrivateKeyParameters (); In the line Return (ECPrivateKeyParameters) PrivateKeyFactory.CreateKey (privInfo); Because of what this can be?

chengbo commented 7 years ago

Probably because you chose a wrong private key. Please get private key with steps described in README and try again.

FeyverkSoft commented 7 years ago

I have key for working with EC_v1. Need some other? openssl pkcs12 -in PrivateKey.p12 -nodes -out PrivateKey.pem cat PrivateKey.pem return

 -----BEGIN EC PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w
{Private-Key}
-----END EC PRIVATE KEY-----

It seemed strange to me..... 😕 I have only these keys and csr. request_applepay.csr apple_pay.cer B217ACA5C9CC601.p12 err

bdavi19 commented 6 years ago

@FeyverkSoft Were you able to get this working for you? I've hit the same snag.

graham-w2 commented 6 years ago

I had this problem except my private key file looked slightly different (notice no "EC" in the BEGIN tag)

-----BEGIN PRIVATE KEY----- MIGHAgEAMBMGByqGSM ... {etc} -----END PRIVATE KEY-----

I then ran "openssl ec -in privatekeyonly.pem -out tradfile.pem" to output the key in "traditional" format on a file containing just that private key with the output looking like this

-----BEGIN EC PRIVATE KEY----- MHcCAQEEILc/zZdDHbmM ... {etc} -----END EC PRIVATE KEY-----

Using this version of the private key the CreateKey method did not throw the exception and the decryption I was trying worked.