Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)));
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
839 views
Welcome To Ask or Share your Answers For Others

1 Answer

The Crypto++ wiki has a number of examples, including use of the HexEncoder and HexDecoder classes.

From the wiki:

byte decoded[] = { 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 
                   0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 };
string encoded;

StringSource ss(decoded, sizeof(decoded), true,
    new HexEncoder(
        new StringSink(encoded)
    ) // HexEncoder
); // StringSource

cout << encoded << endl;
...

$ ./cryptopp-test.exe
FFEEDDCCBBAA99887766554433221100

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...