Click here to Skip to main content
11,929,950 members (50,999 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


34 bookmarked

SpaceCrypto: A Simple Crypto++ Wrapper

, 20 Sep 2010 GPL3
Rate this:
Please Sign up or sign in to vote.
To simply encrypt\decrypt your data...


This library helps you to develop your applications in a very easy way with Crypto++. It permits a developer with a minimal understanding of C++ to rapidly use a crypting library!

My idea was to help new Crypto++ programmers to avoid using their time reading the Crypto++ manual, and adapting all Crypto++ functions to the C++ standard string type.

Using the Code

The SpaceCrypto namespace is divided into two classes: Crypt and Hash. The first one allows you to perform rapid encrypt\decrypt operations with the most common methods (AES, Twofish, DES,...) using the C++ string type (std::string). The second one performs hashing encryption (SHA, MD5, ...).

Crypto Class Usage

Now we're ready to use the wrapper. The first thing you need to declare is an instance of the Crypt class in the SpaceCrypto namespace. You can use one of the predefined typedefs that includes most of the common algorithms (AES, Blowfish, DES,..), or specify another encryption algorithm in the type name.

Note: In the last case, you need to include the library of the algorithm and specify it in the type name.

#include "cryptopp560\rc6"
SpaceCrypto::Crypt<CryptoPP::RC6> hi;

After declaring an instance of the Crypt class, you must set the plain text, the key, and optionally the IV. The function parameters are self explanatory. Remember that you must specify the incoming string format type (HEX or normal), or it will automatically turn into normal input. You can also specify the output type (setInputMode and set OutputMode). When you're ready to encrypt (or decrypt) your string, you need to call the Encrypt() (or Decrypt()) method. This will return you the processed string.

Error Handling

  • getStatus() will return a boolean value representing the current status of obj (true = error; false=no errors)
  • getErrorMsg() will return a string indicating the current error message

You can only perform one encrypt\decrypt function at a time. To perform another crypt operation with the same Crypto object, you need to call the reset() function. This is a security reason, but it has another explanation... When you call the Encrypt function for the first time (or Decrypt), obj proceeds to encrypt all data. So if you call the Encrypt function again (to retrieve another coded string), it doesn't call the Crypto++ crypting function again, but it will simply return the already encoded string.

Security advise: For this reason, I strongly recommend you to call the reset() function immediately after the conversion, if you don't need to call other functions again, because the plain string and the plain key will remain in the RAM until you delete the object!

Hash Class Usage

The hash function work similar to the crypto class, with some exceptions:

  • Remember that hash functions are one-way, so you can't retrieve the string back.
  • The Hash class offers the addStr function that allows you to add some text to the plain string.

Class Usage (Example)

#include "cryptopp_wrapper.h"

int main()
    cout<<"Space Wrapper TEST!"<<endl<<endl;
    SpaceCrypto::CryptBlowFish hello;
    std::string crypt;
    crypt = hello.Encrypt();
    cout<<"Plain Text: HelloWorld!"<<endl;
    cout<<"Crypt Text: "<<crypt<<endl;
    cout<<"Decrypted Text: "<<hello.Decrypt()<<endl;

Linking Errors

SpaceCrypto cannot compile without including the cryptopp libraries. So, before compiling, read the following:

  1. Download and extract the cryptopp libraries from here.
  2. Compile the cryptopp static library by opening the "cryptlib.dsp" project, and include the generated library in your project (in the linker options).
  3. Insert in your project the cryptopp include folder (main directory).

Important Advise

  • You must include cryptlib.lib in your project in order to compile your code.
  • This is a simple class that helps programmers write simple code. If you need something more complex, you cannot use the class. If you need high level functionality... you must study Crypto++.
  • Predef IV is initialized at "0"; if you want to change it, you can edit the initializeIV function.


  • Better error-exception


  • 06/07/2010 - Added an example into the zip file, tutorial modified
  • 26/06/2010 - SpaceCrypto v.1.0.0 released
  • 20/09/2010 - Updated source code


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Software Developer (Junior) Space Softwares
Italy Italy
We're born in the 2008. From the 2010, we're working for fun at an FPS opensource project.
This isn't a commercial company, is only a group created for fun by some teens

You may also be interested in...

Comments and Discussions

QuestionCode does not compile - Syntax errors. Pin
Member 992264627-Jan-14 10:39
memberMember 992264627-Jan-14 10:39 
QuestionLinux Pin
0xt116-Nov-10 14:44
member0xt116-Nov-10 14:44 
GeneralMy vote of 2 Pin
Aescleal20-Sep-10 22:17
memberAescleal20-Sep-10 22:17 
GeneralRe: My vote of 2 Pin
SpaceSoft21-Sep-10 5:05
memberSpaceSoft21-Sep-10 5:05 
GeneralRe: My vote of 2 Pin
Aescleal21-Sep-10 9:16
memberAescleal21-Sep-10 9:16 
Generalaes returns no valid key length Pin
techs218-Sep-10 7:34
membertechs218-Sep-10 7:34 
AnswerRe: aes returns no valid key length Pin
SpaceSoft21-Sep-10 5:02
memberSpaceSoft21-Sep-10 5:02 
GeneralRe: aes returns no valid key length Pin
Thê ÐT19-Nov-12 14:12
memberThê ÐT19-Nov-12 14:12 
Generalidea nxt addition , pplease help Pin
techs214-Sep-10 8:42
membertechs214-Sep-10 8:42 
GeneralRe: idea nxt addition , pplease help Pin
SpaceSoft15-Sep-10 5:13
memberSpaceSoft15-Sep-10 5:13 
GeneralRe: idea nxt addition , pplease help Pin
techs218-Sep-10 6:44
membertechs218-Sep-10 6:44 
GeneralExcellent wrapper, however-- Pin
emphero995-Jul-10 21:06
memberemphero995-Jul-10 21:06 
GeneralRe: Excellent wrapper, however-- Pin
emphero995-Jul-10 21:20
memberemphero995-Jul-10 21:20 
AnswerRe: Excellent wrapper, however-- [modified] Pin
SpaceSoft6-Jul-10 11:32
memberSpaceSoft6-Jul-10 11:32 
GeneralMy vote of 1 Pin
narfzort29-Jun-10 10:49
membernarfzort29-Jun-10 10:49 
GeneralRe: My vote of 1 Pin
SpaceSoft29-Jun-10 13:26
memberSpaceSoft29-Jun-10 13:26 
GeneralRe: My vote of 1 Pin
Oliver Jennert30-Jun-10 1:15
memberOliver Jennert30-Jun-10 1:15 
GeneralRe: My vote of 1 Pin
SpaceSoft30-Jun-10 3:44
memberSpaceSoft30-Jun-10 3:44 
GeneralRe: My vote of 1 Pin
PatLeCat30-Jun-10 22:10
memberPatLeCat30-Jun-10 22:10 
GeneralRe: My vote of 1 Pin
narfzort1-Jul-10 6:54
membernarfzort1-Jul-10 6:54 
GeneralRe: My vote of 1 Pin
SpaceSoft1-Jul-10 9:26
memberSpaceSoft1-Jul-10 9:26 
GeneralRe: My vote of 1 Pin
narfzort1-Jul-10 9:29
membernarfzort1-Jul-10 9:29 
GeneralRe: My vote of 1 Pin
SpaceSoft1-Jul-10 9:51
memberSpaceSoft1-Jul-10 9:51 
GeneralRe: My vote of 1 Pin
narfzort1-Jul-10 10:04
membernarfzort1-Jul-10 10:04 
GeneralRe: My vote of 1 Pin
SpaceSoft3-Jul-10 15:21
memberSpaceSoft3-Jul-10 15: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.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 20 Sep 2010
Article Copyright 2010 by SpaceSoft
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid