When I use try|catch, the exception returns 'BER decoder error'. So, I checked and found out that the base64 encoded string is not correctly formatted.
Looks like I can't use the Base64Encoder/Decoder like HexEncoder/ Decoder. I made some changes and found out it's working. I had to use like the following to save the Base64 encoded string of keys. -------- Base64Encoder pubString(new StringSink(pubKey)); pub.DEREncode(pubString); pubString.MessageEnd(); -------- To retrieve the public key, I used the following code. -------- StringSource pubStr(pubKey, true, new Base64Decoder); RSAES_OAEP_SHA_Encryptor pub(pubStr); -------- Cheers! Aung On Dec 2, 3:48 pm, Tin Htun Aung <[email protected]> wrote: > Hi All, > > I'm trying to retrieve a RSA (OAEP using SHA) public key from string > using Base64Decoder, and having problem. > > First function, I created a keypair, base64 encode and save in string > as follows: > > --------------- > AutoSeededRandomPool rng; > byte randomBytes[256]; > rng.GenerateBlock(randomBytes, 256); > > RSAES_OAEP_SHA_Decryptor priv(rng, 2048 /*, e*/); > RSAES_OAEP_SHA_Encryptor pub(priv); > > string privKey, pubKey; > priv.AccessKey().Save(Base64Encoder(new StringSink(privKey))); > pub.AccessKey().Save(Base64Encoder(new StringSink(pubKey))); > --------------- > > Then in second function, I tried to retrieve a public key from string > using base64decoder as follows: > > --------------- > Base64Decoder decoder; > decoder.Put((byte*)pubKey.c_str(), pubKey.size()); > decoder.MessageEnd(); > > RSAES_OAEP_SHA_Encryptor pub; > pub.AccessKey().Load(decoder); > --------------- > > At the runtime, when it reached "pub.AccessKey().Load(decoder);" core > dumped. > If I use HexEncoder/Decoder, it works. Is the Base64 having problem or > the way I'm using is wrong? > > I hope somebody can share the knowledge. I'm using crypto++ 5.5.2. > > Regards, > Aung -- 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.
