Hello list, I'm trying to use cryptopp for implementing small lib which will allow me to integrate with Android Pay.
I have difficulties with loading private key into Crypto++ wich is mentioned in https://developers.google.com/android-pay/integration/gateway-processor-integration#using-openssl-to-generate-and-format-a-key private static final String MERCHANT_PRIVATE_KEY_PKCS8_BASE64 = "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgCPSuFr4iSIaQprjj" + "chHPyDu2NXFe0vDBoTpPkYaK9dehRANCAATnaFz/vQKuO90pxsINyVNWojabHfbx" + "9qIJ6uD7Q7ZSxmtyo/Ez3/o2kDT8g0pIdyVIYktCsq65VoQIDWSh2Bdm"; I tried it this way, using PEM_Load: string ecPriv = "-----BEGIN EC PRIVATE KEY-----\n" "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgCPSuFr4iSIaQprjj\n" "chHPyDu2NXFe0vDBoTpPkYaK9dehRANCAATnaFz/vQKuO90pxsINyVNWojabHfbx\n" "9qIJ6uD7Q7ZSxmtyo/Ez3/o2kDT8g0pIdyVIYktCsq65VoQIDWSh2Bdm\n" "-----END EC PRIVATE KEY-----\n"; try { AutoSeededRandomPool prng2; CryptoPP::StringSource ss(ecPriv, true); ECIES<ECP>::PrivateKey privKey; PEM_Load(ss, privKey); bool valid = privKey.Validate(prng2, 3); if(!valid) std::cerr << "EC private key is not valid" << endl; cout << "SUCCESS 2222" << endl; } catch (const CryptoPP::Exception& ex) { std::cerr << ex.what() << endl; exit (1); } And also manually: string PRIV_KEY = "-----BEGIN EC PRIVATE KEY-----\n" "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgCPSuFr4iSIaQprjj\n" "chHPyDu2NXFe0vDBoTpPkYaK9dehRANCAATnaFz/vQKuO90pxsINyVNWojabHfbx\n" "9qIJ6uD7Q7ZSxmtyo/Ez3/o2kDT8g0pIdyVIYktCsq65VoQIDWSh2Bdm\n" "-----END EC PRIVATE KEY-----\n"; static string HEADER = "-----BEGIN EC PRIVATE KEY-----"; static string FOOTER = "-----END EC PRIVATE KEY-----"; size_t pos1, pos2; pos1 = PRIV_KEY.find(HEADER); if(pos1 == string::npos) throw runtime_error("PEM header not found"); pos2 = PRIV_KEY.find(FOOTER, pos1+1); if(pos2 == string::npos) throw runtime_error("PEM footer not found"); // Start position and length pos1 = pos1 + HEADER.length(); pos2 = pos2 - pos1; string keystr = PRIV_KEY.substr(pos1, pos2); // Base64 decode, place in a ByteQueue ByteQueue queue; Base64Decoder decoder; decoder.Attach(new Redirector(queue)); decoder.Put((const byte*)keystr.data(), keystr.length()); decoder.MessageEnd(); try { //CryptoPP::RSA::PrivateKey rsaPrivate; ECIES<ECP>::PrivateKey ePrivate; ePrivate.BERDecodePrivateKey(queue, false /*paramsPresent*/, queue.MaxRetrievable()); AutoSeededRandomPool prng2; bool valid = ePrivate.Validate(prng2, 3); if(!valid) cerr << "RSA private key is not valid" << endl; cout << "SUCCESS" << endl; } catch (const CryptoPP::Exception& ex) { cerr << ex.what() << " BLA_BLA" << endl; exit (1); } But with no luck, always getting: BER decode error Rather strange, but another EC key from pem library worked fine for me: -----BEGIN EC PRIVATE KEY----- MHQCAQEEIMcH2yHJcahaqSB0XdPKr+TotYB38wfV9caILqg9Jj7uoAcGBSuBBAAK oUQDQgAEX7J/7ZwW1rO3HpoGxpYRv0PyvfeGKAmcXDVz3qJefS3ToGHYZhPVIyBY i0xlRDP/EwFMilLCA9Rl/bD0E1hzGg== -----END EC PRIVATE KEY----- What I'm doing wrong here? I'm confused, that openssl successfully parse both of the keys. -- -- You received this message because you are subscribed to the "Crypto++ Users" Google Group. To unsubscribe, send an email to [email protected]. More information about Crypto++ and this group is available at http://www.cryptopp.com. --- You received this message because you are subscribed to the Google Groups "Crypto++ Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
