#include <cryptopp/base64.h>
#include <cryptopp/filters.h>
#include <cryptopp/osrng.h>
#include <cryptopp/rsa.h>
#include <string>

CryptoPP::AutoSeededRandomPool rng;

int main() {
CryptoPP::RSA::PrivateKey private_key;
    private_key.GenerateRandomWithKeySize(rng, 2048);

std::string base64_private_key;
CryptoPP::Base64Encoder private_key_sink(new 
CryptoPP::StringSink(base64_private_key));
    private_key.Save(private_key_sink);

CryptoPP::ArraySource as((const byte *)base64_private_key.data(), 
base64_private_key.size(), true, new CryptoPP::Base64Decoder());
    private_key.Load(as);

return 0;
}

Compiling and running with the following command occasionally fails with a 
decoding error
g++ save_then_load.cc -lcrypto++ && ./a.out

Error:
terminate called after throwing an instance of 'CryptoPP::BERDecodeErr'
  what():  BER decode error
Aborted (core dumped)

Are there any caveats in those Load and Save function that I am missing?

-- 
You received this message because you are subscribed to "Crypto++ Users". More 
information about Crypto++ and this group is available at 
http://www.cryptopp.com and 
http://groups.google.com/forum/#!forum/cryptopp-users.
--- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/cryptopp-users/c11b3185-0767-4cc0-8b79-1b0b945dd570%40googlegroups.com.

Reply via email to