(Answer) (Category) Crypto++ Faq-O-Matic :
How do I use hex encoding and decoding?
Moderator: weidai (inherited from parent)
Encoding

Encoding is very simple, say we had some data 'pData'
that was of length 'dwLen', that we wished to encode
and store in 'pData2' which is of length 'dwLen'*2,
then

   #include "hex.h" // from crypto++ library

   HexEncoder hexEncoder;
   hexEncoder.Put(pData,dwLen);
   hexEncoder.MessageEnd();
   hexEncoder.Get(pData2,dwLen*2);

And there we have it. It is also possible to add multiple blocks of data to the
encoders stream i.e.

   HexEncoder hexEncoder;
   hexEncoder.Put(pDataA,dwLenA);
   hexEncoder.Put(pDataB,dwLenB);
   hexEncoder.Put(pDataC,dwLenC);
   hexEncoder.MessageEnd();
   hexEncoder.Get(pData2,(dwLenA+dwLenB+dwLenC)*2);


Decoding

Decoding is equally simple.

   HexDecoder hexDecoder;
   hexDecoder.Put(pData,dwLen);
   hexDecoder.MessageEnd();
   hexDecoder.Get(pData2,dwLen/2);
2001-Jan-12 10:55pm shaun_wilde, weidai
See http://www.cryptopp.com/cgi-bin/fom.cgi?file=29 for more information on using Filters, which applies to these hex encoding and decoding filters.
2006-Dec-11 10:52pm weidai
[Append to This Answer]
2006-Dec-11 10:52pm
Previous: (Answer) How do I use the Filter class?
Next: (Answer) How do I use a block cipher in Crypto++ 4.x?
This document is: http://www.cryptopp.com/cgi-bin/fom.cgi?file=37
[Search] [Appearance] [Show Expert Edit Commands]
This is a Faq-O-Matic 2.721.
This FAQ is administered by Wei Dai.