Shaun Wilde">
Click here to Skip to main content
15,356,336 members
Articles / Programming Languages / C++
Posted 20 Nov 2000


33 bookmarked

Hex Encoder and Decoder using Crypto++

Rate me:
Please Sign up or sign in to vote.
3.31/5 (8 votes)
20 Nov 2000CPOL
Encode binary data to and from hexadecimal format using the Crypto++ library


The Crypto++ library is a freeware library of cryptographic schemes, written by Wei Dai. However the library also contains other useful classes which one is not made immediately aware of when you use the library. Two of these are the HexEncoder and HexDecoder classes which can be used to (surprise, surprise) encode and decode data to and from the hexadecimal text format e.g. 0-9,A-F.


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;

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

HexEncoder hexEncoder;


Decoding is equally simple.

HexDecoder hexDecoder;


Thanks to Wei Dai for his permission to write this article in what is hoped to be a series of articles on the use of his Crypto++ library.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shaun Wilde
Employed (other) Purplebricks
Australia Australia
All articles are supplied as-is, as a howto on a particular task that worked for me in the past. None of the articles are supposed to be out-of-the-box freeware controls and nor should they be treated as such. Caveat emptor.

Now living and working in Australia, trying to be involved in the local .NET and Agile communities when I can.

I spend a good chunk of my spare time building OpenCover and maintaining PartCover both of which are Code Coverage utilities for .NET.

Comments and Discussions

QuestionFunction HexEncoder::Close not found [modified] Pin
luozhaotian20-Dec-08 17:16
Memberluozhaotian20-Dec-08 17:16 
AnswerRe: Function HexEncoder::Close not found Pin
Shaun Wilde21-Dec-08 0:25
MemberShaun Wilde21-Dec-08 0:25 
GeneralCrypto++ Integration Article Pin
Jeffrey Walton8-Dec-06 18:33
MemberJeffrey Walton8-Dec-06 18:33 
GeneralRe: Crypto++ Integration Article Pin
Shaun Wilde8-Dec-06 19:34
MemberShaun Wilde8-Dec-06 19:34 
QuestionHelp me please?? Pin
xxhimanshu4-Nov-03 23:12
Memberxxhimanshu4-Nov-03 23:12 
AnswerRe: Help me please?? Pin
Shaun Wilde5-Nov-03 7:38
MemberShaun Wilde5-Nov-03 7:38 
Generalwe need more help Pin
4-Feb-02 21:52
suss4-Feb-02 21:52 
GeneralRe: we need more help Pin
SAWilde5-Feb-02 9:21
MemberSAWilde5-Feb-02 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.