I'm new to Cryptopp and I wanted to encode text and decode back to understand how it works. The encoding part works fine but I cannot get the string decoded? Always the decoded string is empty. I asked in Crypto mailing and someone said this code should work but it does not.
I would like to know what is wrong. Being new to crypto I cannot see what is wrong.
The code:
std::string encoded = m_pkey->GetValue().ToStdString();//here under debugger its ok
std::string decoded;
CryptoPP::StringSource(encoded, true, new CryptoPP::HexDecoder(new CryptoPP::StringSink(decoded)));
The Crypto++ wiki has a number of examples, including use of the HexEncoder and HexDecoder classes.
From the wiki:
The model used in the above answer is what is referred to as the "pipeline" pattern in Crypto++. See Crypto++ article on pipelining
Note the rules that apply to object ownership - if you pass a pointer to an object into a constructor, that object will be owned by the newly constructed object and deleted in its destructor. If the object is passed into the constructor by reference, the object must remain extant for the life of the newly constructed object, i.e. you retain ownership and must not delete it from under the nose of the new object!