> 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";
>
> My bad... I missed that you were already using the PEM Pack.

Try this, it works for me:

#include <iostream>
#include <string>
using namespace std;

#include "files.h"
#include "filters.h"
#include "base64.h"
#include "osrng.h"
#include "eccrypto.h"
using namespace CryptoPP;

string encoded =
    "MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgCPSuFr4iSIaQprjj"
    "chHPyDu2NXFe0vDBoTpPkYaK9dehRANCAATnaFz/vQKuO90pxsINyVNWojabHfbx"
    "9qIJ6uD7Q7ZSxmtyo/Ez3/o2kDT8g0pIdyVIYktCsq65VoQIDWSh2Bdm";

int main(int argc, char* argv[])
{
    try
    {
        string decoded;
        StringSource ss1(encoded.c_str(), true, new Base64Decoder(new 
StringSink(decoded)));        
        StringSource ss2((const byte*)decoded.data(), decoded.size(), true, 
new FileSink("key.der"));

        DL_PrivateKey_EC<ECP> key;
        key.Load(StringStore((const byte*)decoded.data(), 
decoded.size()).Ref());

        AutoSeededRandomPool prng;
        key.ThrowIfInvalid(prng, 3);
        
        cout << "Private key appears to be valid" << endl;
    }
    catch(Exception& ex)
    {
        cerr << ex.what() << endl;
        return 1;
    }
    
    return 0;
}

And:

$ g++ -DNDEBUG -g2 -O2 -I . test.cxx -o test.exe ./libcryptopp.a
$ ./test.exe
Private key appears to be valid

-- 
-- 
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.

Reply via email to