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 72 73 74 75 76 77 78 79 80 81
| #pragma once
#pragma warning( disable: 4275 ) #pragma warning( disable: 4819 )
#include <iostream>
#include <cryptopp/dll.h> #include <cryptopp/cryptlib.h> #include <cryptopp/aes.h> #include <cryptopp/filters.h> #include <cryptopp/modes.h>
using namespace std;
USING_NAMESPACE(CryptoPP)
class CipherApiImpl { public: enum MODE { AES, DES };
public: CipherApiImpl(MODE mode = MODE::AES);
int get_filesize(const char *filename);
int save(const std::string& filepath, const std::string& str); std::string load(const std::string& filepath); std::string encrypt_string(const std::string& plain_text); std::string decrypt_string(const std::string& cipher_text);
std::string encrypt_file(const std::string& infile); std::string decrypt_file(const std::string& infile);
int encrypt_file(const std::string& infile, const std::string& outfile); int decrypt_file(const std::string& infile, const std::string& outfile);
protected: std::string tohex(const char& c); std::string tohexs(const std::string& str);
char tochar(const char& hex1, const char& hex2); std::string tochars(const std::string& hex);
private: const byte aes_key[CryptoPP::AES::MAX_KEYLENGTH] = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef }; const byte aes_iv[CryptoPP::AES::BLOCKSIZE] = { 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef, 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef };
const byte des_key[CryptoPP::DES_EDE3::MAX_KEYLENGTH] = { 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef, 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef }; const byte des_iv[CryptoPP::DES_EDE3::BLOCKSIZE] = { 0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef };
CryptoPP::CFB_FIPS_Mode<CryptoPP::AES>::Encryption aes_encryption; CryptoPP::CFB_FIPS_Mode<CryptoPP::AES>::Decryption aes_decryption;
CryptoPP::CFB_FIPS_Mode<CryptoPP::DES_EDE3>::Encryption des_encryption; CryptoPP::CFB_FIPS_Mode<CryptoPP::DES_EDE3>::Decryption des_decryption;
MODE m_mode; };
|