#include #include //#include "crypto++/HASHCrypt.hpp" #include #include #include using CryptoPP::HexEncoder; using CryptoPP::HexDecoder; #include using CryptoPP::BufferedTransformation; using CryptoPP::AuthenticatedSymmetricCipher; #include using CryptoPP::SecByteBlock; #include using CryptoPP::CFB_Mode; #include using CryptoPP::StringSink; using CryptoPP::StringSource; using CryptoPP::AuthenticatedEncryptionFilter; using CryptoPP::AuthenticatedDecryptionFilter; #include using CryptoPP::AutoSeededRandomPool; #include using CryptoPP::AES; #include #include using CryptoPP::GCM; using CryptoPP::GCM_TablesOption; void getKI(std::string chaine,byte* key, byte* iv, int size){ CryptoPP::MD5 hash; byte digest[ CryptoPP::MD5::DIGESTSIZE ]; std::string message = chaine; hash.CalculateDigest( digest, (byte*) message.c_str(), message.length() ); CryptoPP::HexEncoder encoder; std::string output; encoder.Attach( new CryptoPP::StringSink( output ) ); encoder.Put( digest, sizeof(digest) ); encoder.MessageEnd(); for(int i=0; i::Encryption* enc = new CFB_Mode::Encryption(key, size, iv, 1); // the final argument is specific to CFB mode, and specifies the refeeding size in bytes. This invocation corresponds to Java's Cipher.getInstance("AES/CFB8/NoPadding") CryptoPP::CFB_Mode::Decryption* dec = new CFB_Mode::Decryption(key, size, iv, 1); } void aff(std::string chaine); //#include "crypto++/sha3.h" int main(){ /* /home/loic/Documents/c/forgetIt/crypto++/HASHCrypt.cpp|21aff("------------------\n"); HASHCrypt monhash=HASHCrypt("loic"); aff(monhash.getMD5_128()); aff("\n"); aff("--------------\n");*/ std::string MessageS="Bonjours les amis, je vais être crypter !!!!"; char* Message=(char*)MessageS.c_str(); std::cout << Message << std::endl; AutoSeededRandomPool rnd; // Generate a random key //SecByteBlock key(0x00, AES::DEFAULT_KEYLENGTH); //rnd.GenerateBlock( key, key.size() ); // Generate a random IV //byte iv[AES::BLOCKSIZE]; //rnd.GenerateBlock(iv, AES::BLOCKSIZE); std::string cle; aff("Entrez une clé de cryptage : "); std::cin >> cle; byte key[32]; byte iv[32]; getKI(cle,key,iv, sizeof(key)); int messageLen = (int)strlen(Message) + 1; ////////////////////////////////////////////////////////////////////////// // Encrypt CFB_Mode::Encryption cfbEncryption(key, sizeof(key), iv); cfbEncryption.ProcessData((byte*)Message, (byte*)Message, messageLen); while(not(cle=="exit")){ byte key2[32]; byte iv2[32]; MessageS="Bonjours les amis, je vais être crypter !!!!"; CFB_Mode::Encryption cfbEncryption(key, sizeof(key), iv); cfbEncryption.ProcessData((byte*)Message, (byte*)Message, messageLen); aff("Entrez une clé de décryptage : "); std::cin >> cle; getKI(cle,key2,iv2, sizeof(key)); ////////////////////////////////////////////////////////////////////////// // Decrypt std::cout << std::endl << "Decryptage : " << std::endl; CFB_Mode::Decryption cfbDecryption(key2,sizeof(key2), iv2); cfbDecryption.ProcessData((byte*)Message, (byte*)Message, messageLen); std::cout <