Hi Ben, > privateKey.Save(Base64Encoder(new StringSink(priv)).Ref()); I've run into it before with the encoders and have worked around. I seem to recall using something similar to:
Base64Encoder encoder(...); encoder.Put(...); encoder.MessageEnd(); I suspect it because a BufferedTransformation in the chain is buffering, and the suspect (Base64Encoder) does not have a 'pumpAll' to force the message through. See http://www.cryptopp.com/docs/ref/class_base64_encoder.html. Jeff On Oct 11, 3:06 pm, Ben Botto <[email protected]> wrote: > 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.
