While working on a client-server based app, I suddenly came face to face with the need to secure and authenticate certain commands between the client and server. I was certain there was a library out there to meet my needs and I was right. I rapidly came across the Crypto++ library, a powerful set of cryptographic tools written and tested by experts. I was in heaven! Think of the time this has saved me!
There was only one problem. The Crypto++ library is indeed a very powerful set of cryptographic tools, but I found the learning curve to get my first apps running with it to be very high. I examined all the sample code I could find, worked through the API documentation, and examined the validation and test code before I finally started catching on. Then I had to “grep” my way through the files to identify which headers I needed to include for a given function.
DISCLAIMER: All of this brainache is undoubtedly due to my own lack of skill and formal training.
Nevertheless, I overcame my deficiencies and learned how to encrypt and decrypt at will. But, I was unhappy with the amount of extra code I had to put everywhere I wanted to encrypt and decrypt something. So, I ended up writing a simplification wrapper to make my work easier. My wrapper uses only a small subset of functionality and algorithms in Crypto++, but it makes using that subset very easy.
As a very small example, here is how you encrypt a given plaintext string:
string cipherText = BasicCryptoPPWrap::EncryptStringAES(“Encrypt me”, key, initVector, errFlag, errMsg);
The wrapper also implements a custom Advanced Encryption Standard protocol that stores the initial vector with the encrypted data, so you don’t have to track it yourself. I have used this wrapper very successfully in my own work, I think you’ll find it useful too!
Wrapper functions:
- Implements symmetrical AES encryption and decryption
- Hex encoding of binary data
- Hex decoding of hex-coded strings
- Generic string and file encryption
- Custom protocol string and file encryption
- Random bit and byte generators
- SHA-256 Hash generator
The wrapper is not a standalone solution. It requires your code to link to libcryptopp and know where the cryptopp header files are found. The Crypto++ website can help you set up your system. Once you get the validation suite to run successfully, you will be able to use this wrapper.
Get the files here:
- BasicCryptoPPWrap.h – The header file that makes it all happen
- example.cpp – An example file that takes you through all the functions available in the wrapper
Good luck! I release this wrapper into the public domain, but if you happen to use the code I wouldn’t mind hearing about it! Credit might be nice too!
Mike