Saturday, March 16, 2013

How to Install Crypto++ Library with the Eclipse IDE on UBUNTU12.10 OS.

C++ - How to install Cryptopp /  Crypto++ Library with the Eclipse IDE on UBUNTU12.10 OS.

Install Crypto++ library with Ubuntu with the following command

$ sudo apt-get install libcrypto++-dev libcrypto++-doc libcrypto++-utils

Now make a empty new C++ project in Eclipse IDE
Then add the libraries in the Eclipse ide by following instruction.
Right click the project hello and go to properties.
Then go to

 Tool Settings->Cross G++ Linker ->Libraries-> and do the settings as Shown in picture

And then try the following program for crypto++

#include <iostream>
#include <iomanip>

#include "modes.h"
#include "aes.h"
#include "filters.h"

int main(int argc, char* argv[]) {

    // Key and IV setup
    //AES encryption uses a secret key of a variable length (128-bit, 196-bit or 256-   
    //bit). This key is secretly exchanged between two parties before communication   
    //begins. DEFAULT_KEYLENGTH= 16 bytes
    byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ];
    memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH );
    memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE );

    // String and Sink setup
    std::string plaintext = "Now is the time for all good men to come to the aide...";
    std::string ciphertext;
    std::string decryptedtext;

    // Dump Plain Text
    std::cout << "Plain Text (" << plaintext.size() << " bytes)" << std::endl;
    std::cout << plaintext;
    std::cout << std::endl << std::endl;

    // Create Cipher Text
    CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
    CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, iv );

    CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink( ciphertext ) );
    stfEncryptor.Put( reinterpret_cast<const unsigned char*>( plaintext.c_str() ), plaintext.length() + 1 );

    // Dump Cipher Text
    std::cout << "Cipher Text (" << ciphertext.size() << " bytes)" << std::endl;

    for( int i = 0; i < ciphertext.size(); i++ ) {

        std::cout << "0x" << std::hex << (0xFF & static_cast<byte>(ciphertext[i])) << " ";

    std::cout << std::endl << std::endl;

    // Decrypt
    CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
    CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );

    CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink( decryptedtext ) );
    stfDecryptor.Put( reinterpret_cast<const unsigned char*>( ciphertext.c_str() ), ciphertext.size() );

    // Dump Decrypted Text
    std::cout << "Decrypted Text: " << std::endl;
    std::cout << decryptedtext;
    std::cout << std::endl << std::endl;

    return 0;
And Run the program the program should work perfectly.


  1. dear sir
    thanks allot for your help i have tried those steps but i got an error on eclipse
    ../src/MasterCrypto.cpp:20:19: fatal error: modes.h: No such file or directory
    compilation terminated.
    i don't know if i made something wrong or not

    1. try:
      properties->c++ general->paths and symbols->includes
      then add the folders:usr/include/cryptopp and usr/include/crypto++
      hope it will help you!

  2. I loved the way you did it, many thanks for this tutorial

  3. Great article. I am trying same on the windows using eclipse but getting the error "/usr/bin/ld: cannot find -llibcryptopp". Eclipse is setting the correct lib path in -L compiler option but is not able to find the lib.
    Thanks in advance

  4. This comment has been removed by the author.

  5. This comment has been removed by the author.