1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| string encryptAES(string& plain, CryptoPP::byte* key){ std::string cipher, encoded; ECB_Mode<AES>::Encryption e; e.SetKey(key, 16); StringSource ss1(plain, true, new StreamTransformationFilter(e, new StringSink(cipher)) ); std::cout << "(AES) The cipher text is: " << cipher << std::endl; StringSource ss2( cipher, true, new HexEncoder( new StringSink( encoded ) ) ); std::cout << "(AES) The hex text is: " << encoded << std::endl; return cipher; }
string decryptAES(string& cipher, CryptoPP::byte* key){ std::string recovered; ECB_Mode<AES>::Decryption d; d.SetKey(key, 16); StringSource ss1(cipher, true, new StreamTransformationFilter(d, new StringSink(recovered)) ); std::cout << "(AES) The recovered text is: " << recovered << std::endl; return recovered; }
string encryptDES(string& plain, CryptoPP::byte* key){ string cipher, encoded; ECB_Mode<DES>::Encryption e; e.SetKey(key, 8); StringSource ss1(plain, true, new StreamTransformationFilter(e, new StringSink(cipher)) ); std::cout << "(DES) The cipher text is: " << cipher << std::endl; StringSource ss2( cipher, true, new HexEncoder( new StringSink( encoded ) ) ); std::cout << "(DES) The hex text is: " << encoded << std::endl; return cipher; }
string decryptDES(string& cipher, CryptoPP::byte* key){ std::string recovered; ECB_Mode<DES>::Decryption d; d.SetKey(key, 8); StringSource ss1(cipher, true, new StreamTransformationFilter(d, new StringSink(recovered)) ); std::cout << "(DES) The recovered text is: " << recovered << std::endl; return recovered; }
|