Crypto++ is a set of open source libraries on the application of cryptography, which provides many useful algorithms such as hashing (MD5, SHA), Data encryption (DES, AES), digital signature (RSA, Elliptic curve Signature Algorithm ECDSA), and the algorithm security has been through FIPS 140-2 (http:/ /csrc.nist.gov/cryptval/140-2.htm) validation. crypto++ Library contains a large number of algorithms
1, group password: des-ede3, Blowfish, Rijndael
2, serial password:
3, hash function: SHA1
4. Message Authentication code: HMAC/SHA1
5, Public key encryption: RSA/OAEP/SHA1
6, Signature: RSA/PKCS1V15/SHA1, DSA,GENERALIZED-DSA/SHA1
7. Key agreement: DH
8. Random number generator: Randompool,autoseededrandompool
crypto++ Installation:
crypto++ Official Download: Click to download
Download it and unzip it directly, then open the solution Cryptest.sln in VS2015 or other VS versions, open with 4 projects, open the cryptlib.cpp of the Cryptlib project, and compile separately in debug mode and release mode.
The compile time is relatively long and will generate cryptlib.lib this library file when finished. After downloading the extracted crypto++ named Cryptopp, copy to the compiler's include directory (for example: F:\VS2015pro\VC\include), copy cryptlib.lib files to the compiler's Lib directory. So we just need to explain the link cryptlib.lib. For example, in VS2015, add "->" to the project-> property-> linker-> command line cryptlib.lib additional options. Test for success, create a new project, copy the following code, and then successfully run the description configuration successfully.
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <cryptopp/aes.h>
using namespace Cryptopp;
int main ()
{
cout << "Hello crypto++" << Endl;
cout << "Aes block size is" << aes::blocksize << Endl;
System ("pause");
return 0;
Run the results as shown in figure:
Create crypto++ SDK
New folder in C:\ProgramFiles\, named "Cryptopp", Inside the new folder "include", "Lib", in the "Lib" New Folder "Debug", "release." Copy all the header files from the crypto++ library to the Include folder, and then copy the two cryptlib.lib that were generated above to Debug and release.
Set engineering Properties
Select Engineering Properties (Alt +F7):
(1) "Configuration Properties" → "c/n + +" → "general", the right "additional include directory" set for the above built crypto++ SDK include folder, "C:\Program Files\cyptopp\include";
(2) configuration Properties "→ linker" → "general", the right "additional library directory" set to the above built crypto++ SDK Lib\debug folder, "C:\Program Files\cyptopp\lib\debug" (Release mode corresponds to the release folder);
(3) "Configuration Properties" → "c/C + +" → "code generation", the right "runtime" set to "multithreaded Debugging (/MTD)" (in release mode corresponds to "multi-threaded (/MT)")
Now you can use everything in crypto++.
For example, the RSA algorithm:
#include "randpool.h" #include "rsa.h" #include "hex.h" #include "files.h" #include <iostream> #include <std
Lib.h> using namespace std;
using namespace Cryptopp; #pragma comment (lib, "Cryptlib.lib")//------------------------//function declaration//------------------------void Generatersake
Y (unsigned int keylength, const char *privfilename, const char *pubfilename, const char *seed);
String rsaencryptstring (const char *pubfilename, const char *seed, const char *message);
String rsadecryptstring (const char *privfilename, const char *ciphertext);
Randompool & Globalrng (); ------------------------//Main program//------------------------void Main () { char prikey[128] = {0
};
char pubkey[128] = {0};
char seed[1024] = {0}; //generates RSA key pair strcpy (Prikey, "pri"); Generated private key file strcpy (PubKey, "pub"); Generated public key file strcpy (seed, "seed");
generatersakey (1024, Prikey, PubKey, Seed);
//RSA plus decryption char message[1024] = {0};
cout << "Origin text:\t" << "Hello world!" << Endl << Endl;
strcpy (Message, "Hello world!"); string encryptedtext = rsaencryptstring (PubKey, seed, message);
RSA encryption cout << "Encrypted text:\t" << encryptedtext << endl << Endl; string decryptedtext = rsadecryptstring (Prikey, Encryptedtext.c_str ());
RSA decryption cout << "decrypted text:\t" << decryptedtext << endl << Endl;
system ("pause"); }//------------------------//Generate RSA key pair//------------------------void Generatersakey (unsigned int keylength, const
Char *privfilename, const char *pubfilename, const char *seed) { randompool randpool; ranDpool.put ((BYTE *) seed, strlen (seed));
rsaes_oaep_sha_decryptor priv (Randpool, keylength);
hexencoder Privfile (New Filesink (Privfilename)); priv.
Derencode (Privfile);
privfile.messageend ();
rsaes_oaep_sha_encryptor Pub (PRIV);
hexencoder Pubfile (New Filesink (Pubfilename)); pub.
Derencode (Pubfile);
pubfile.messageend (); }//------------------------//RSA encryption//------------------------string rsaencryptstring (const char *pubfilename, con
St Char *seed, const char *message { filesource pubfile (Pubfilename, True, new Hexdecoder);
rsaes_oaep_sha_encryptor Pub (pubfile);
randompool Randpool;
randpool.put ((byte) seed, strlen (seed));
string result; stringsource (Message, True, new Pk_encryptorfilter (Randpool, Pub, New Hexencoder (new Stringsink (result)));
return result; }//------------------------//RSA decryption//------------------------string rsadecryptstring (const char *privfilename, CO
NST Char *ciphertext { filesource privfile (Privfilename, True, new Hexdecoder);
rsaes_oaep_sha_decryptor Priv (privfile);
string result; stringsource (ciphertext, True, new Hexdecoder (New Pk_decryptorfilter (Globalrng (), Priv, new
Stringsink (result)));
return result; //------------------------//definition of global random number pool//------------------------Randompool & Globalrng () { &N
Bsp;static Randompool Randompool;
return Randompool;
}