Crypto++ Setup in Linux

Download Crypto++ library source from https://www.cryptopp.com/#download

Unzip it and put it in a convenient location

Go inside the directory and run

make
make install

It will install the library in default location

Write the program as shown below to calculate MD5sum

//main.cpp
#define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1
#include <ctime>
#include <iostream>
#include "cryptopp565/modes.h"
#include "cryptopp565/md5.h"
#include "cryptopp565/hex.h"
using namespace std;

string getMD5Hash(string message){
	CryptoPP::Weak::MD5 hash;
	byte digest[ CryptoPP::Weak::MD5::DIGESTSIZE ];

	hash.CalculateDigest( digest, (byte*) message.c_str(), message.length() );

	CryptoPP::HexEncoder encoder;
	string output;
	encoder.Attach( new CryptoPP::StringSink( output ) );
	encoder.Put( digest, sizeof(digest) );
	encoder.MessageEnd();

	cout << "Calculated MD5 Hash. Mesage: " << message << " | hash: " << output << endl;

	return output;
}

int main()
{
	cout << getMD5Hash("Hello World!") << endl;

	return 0;
}

Then we can compile it using -L/usr/local/lib -lcryptopp flag.

g++ -std=c++11 main.cpp -L/usr/local/lib -lcryptopp

Crypto++ library is very vast. This is a simple example of finding MD5sum.

Advertisements