Decoding Hex Encoded Value with Crypto++

余生颓废 提交于 2019-11-29 16:55:30

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

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!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!