For some reason I cannot correctly save and load keys using Base64.
If I save a key using a HexEncoder, then load the key it works every
time.  On the other hand, if I save a key using a Base64Encoder and
then try to load the key it works about half the time, the rest of the
time I get a BER decode error.  Please see the below code - using
HexEncoder works, Base64Encoder fails.  Am I doing something
incorrectly?  Any input is greatly appreciated.
------------------------------------------------------
#include <iostream>
#include <crypto++/rsa.h>
#include <crypto++/osrng.h>
#include <crypto++/files.h>
#include <crypto++/filters.h>
#include <crypto++/hex.h>
#include <crypto++/base64.h>
#include <string>
#include <cstring>
using namespace std;
using namespace CryptoPP;

int main(int argc, char* argv[])
{
  try
  {
    RSA::PrivateKey        privateKey;
    AutoSeededRandomPool   rng;
    InvertibleRSAFunction  params;
    string                 pub, priv;

    params.GenerateRandomWithKeySize(rng, 2048);
    privateKey.AssignFrom(params);

    privateKey.Save(Base64Encoder(new StringSink(priv)).Ref());
    //privateKey.Save(HexEncoder(new StringSink(priv)).Ref());

    //cout << endl << priv << endl << endl;

    privateKey.Load(StringSource(priv, true, new
Base64Decoder()).Ref()); /*FAIL*/
    //privateKey.Load(StringSource(priv, true, new
HexDecoder()).Ref());
  }
  catch (Exception e)
  {
    cout << e.what() << endl;
  }
  return 0;
}

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

Reply via email to