diff --git a/aesclass/aesclass.cpp b/aesclass/aesclass.cpp new file mode 100644 index 0000000..e1b91a9 --- /dev/null +++ b/aesclass/aesclass.cpp @@ -0,0 +1,162 @@ +#include "aesclass.h" + +AESClass::AESClass() +{ + memset(key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH); + memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE); +} + +AESClass::~AESClass() +{ + memset(key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH); + memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE); +} + +void AESClass::setKey(byte* _key) +{ + memcpy(key, _key, CryptoPP::AES::DEFAULT_KEYLENGTH); +} + +void AESClass::setKey(const char *_key) +{ + memcpy(key, _key, CryptoPP::AES::DEFAULT_KEYLENGTH); +} + +void AESClass::setKey(std::string _key) +{ + memcpy(key, _key.c_str() , CryptoPP::AES::DEFAULT_KEYLENGTH); +} + +void AESClass::setIv(byte *_iv) +{ + memcpy(iv, _iv, CryptoPP::AES::BLOCKSIZE); +} + +void AESClass::setIv(const char *_iv) +{ + memcpy(iv, _iv, CryptoPP::AES::BLOCKSIZE); +} + +void AESClass::setIv(std::string _iv) +{ + memcpy(iv, _iv.c_str() , CryptoPP::AES::BLOCKSIZE); +} + +const int AESClass::getKeyLength() const +{ + return CryptoPP::AES::DEFAULT_KEYLENGTH; +} + +const int AESClass::getBlockSize() const +{ + return CryptoPP::AES::BLOCKSIZE; +} + +const byte* AESClass::getKey() const +{ + return key; +} + +const byte* AESClass::getIv() const +{ + return iv; +} + + +std::string AESClass::AESEncrypt(std::string plaintext) +{ + std::string ciphertext; + CryptoPP::AES::Encryption + aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH); + CryptoPP::CBC_Mode_ExternalCipher::Encryption + cbcEncryption(aesEncryption, iv); + + CryptoPP::StreamTransformationFilter + stfEncryptor(cbcEncryption, new CryptoPP::StringSink( ciphertext)); + stfEncryptor.Put(reinterpret_cast + (plaintext.c_str()), plaintext.size() + 1); + stfEncryptor.MessageEnd(); + + return ciphertext; +} + +std::string AESClass::AESEncrypt(char *_plaintext) +{ + std::string plaintext(_plaintext); + return AESEncrypt(plaintext); +} + +std::string AESClass::AESDecrypt(byte* _ciphertext) +{ + std::string ciphertext((char *)_ciphertext); + return AESDecrypt(ciphertext); +} + +std::string AESClass::AESDecrypt(std::string _ciphertext) +{ + std::string decryptedtext; + CryptoPP::AES::Decryption aesDecryption(key, + CryptoPP::AES::DEFAULT_KEYLENGTH); + CryptoPP::CBC_Mode_ExternalCipher::Decryption + cbcDecryption(aesDecryption, iv ); + + CryptoPP::StreamTransformationFilter + stfDecryptor(cbcDecryption, new CryptoPP::StringSink(decryptedtext)); + stfDecryptor.Put( reinterpret_cast + (_ciphertext.c_str()), _ciphertext.size()); + stfDecryptor.MessageEnd(); + + return decryptedtext; +} + +std::string AESClass::toBase64(byte* _ciphertext) +{ + std::string ciphertext((char *)_ciphertext); + return toBase64(ciphertext); +} + +std::string AESClass::toBase64(std::string _ciphertext) +{ + std::string base64encodedciphertext; + CryptoPP::StringSource(_ciphertext, true, + new CryptoPP::Base64Encoder( + new CryptoPP::StringSink(base64encodedciphertext) + ) // Base64Encoder + ); // StringSource + return base64encodedciphertext; +} + +void AESClass::base64toByte(std::string text, byte* out) +{ + std::string base64decryptedciphertext; + CryptoPP::StringSource(text, true, + new CryptoPP::Base64Decoder( + new CryptoPP::StringSink( base64decryptedciphertext) + ) // Base64Encoder + ); + + memcpy(out, base64decryptedciphertext.c_str(), base64decryptedciphertext.size()); +} +std::string AESClass::base64toString(std::string text) +{ + std::string out; + CryptoPP::StringSource(text, true, + new CryptoPP::Base64Decoder( + new CryptoPP::StringSink(out) + ) // Base64Encoder + ); + return out; +} + +void AESClass::hex2byte(const char *in, unsigned int len, byte *out) +{ + for (unsigned int i = 0; i < len; i+=2) { + char c0 = in[i+0]; + char c1 = in[i+1]; + byte c = ( + ((c0 & 0x40 ? (c0 & 0x20 ? c0-0x57 : c0-0x37) : c0-0x30)<<4) | + ((c1 & 0x40 ? (c1 & 0x20 ? c1-0x57 : c1-0x37) : c1-0x30)) + ); + out[i/2] = c; + } +} diff --git a/aesclass/aesclass.h b/aesclass/aesclass.h new file mode 100644 index 0000000..1399e9c --- /dev/null +++ b/aesclass/aesclass.h @@ -0,0 +1,43 @@ +#ifndef AESCLASS +#define AESCLASS +#include +#include "../cryptopp563/cryptlib.h" +#include "../cryptopp563/modes.h" +#include "../cryptopp563/aes.h" +#include "../cryptopp563/filters.h" +#include "../cryptopp563/base64.h" +#include +class AESClass +{ +private: + byte key[CryptoPP::AES::DEFAULT_KEYLENGTH]; + byte iv[CryptoPP::AES::BLOCKSIZE]; + +public: + AESClass(); + ~AESClass(); + void setKey(byte* _key); + void setKey(const char *_key); + void setKey(std::string _key); + void setIv(byte* _iv); + void setIv(const char *_iv); + void setIv(std::string _iv); + const byte* getKey() const; + const byte* getIv() const; + const int getKeyLength() const; + const int getBlockSize() const; + std::string AESEncrypt(std::string plaintext); + std::string AESEncrypt(char *_plaintext); + + std::string AESDecrypt(byte* _ciphertext); + std::string AESDecrypt(std::string _ciphertext); + static void hex2byte(const char *in, unsigned int len, byte *out); + static std::string toBase64(byte* _ciphertext); + static std::string toBase64(std::string _ciphertext); + void base64toByte(std::string text, byte* out); + std::string base64toString(std::string text); +}; + + +#endif // AESCLASS + diff --git a/aesclass/aesclass.pro b/aesclass/aesclass.pro new file mode 100644 index 0000000..c1a7782 --- /dev/null +++ b/aesclass/aesclass.pro @@ -0,0 +1,35 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2016-02-12T15:41:49 +# +#------------------------------------------------- + +QT += core + +QT -= gui + +TARGET = aesclass +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += main.cpp \ + aesclass.cpp + +HEADERS += \ + aesclass.h + +win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../cryptopp563/ -lcryptlib +else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../cryptopp563/ -lcryptlibd +else:unix: LIBS += -L$$PWD/../cryptopp563/ -lcryptlib + +INCLUDEPATH += $$PWD/../cryptopp563 +DEPENDPATH += $$PWD/../cryptopp563 + +win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../cryptopp563/libcryptlib.a +else:win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../cryptopp563/libcryptlibd.a +else:win32:!win32-g++:CONFIG(release, debug|release): PRE_TARGETDEPS += $$PWD/../cryptopp563/cryptlib.lib +else:win32:!win32-g++:CONFIG(debug, debug|release): PRE_TARGETDEPS += $$PWD/../cryptopp563/cryptlibd.lib +else:unix: PRE_TARGETDEPS += $$PWD/../cryptopp563/libcryptlib.a diff --git a/aesclass/aesclass.pro.user b/aesclass/aesclass.pro.user new file mode 100644 index 0000000..87ce7ba --- /dev/null +++ b/aesclass/aesclass.pro.user @@ -0,0 +1,816 @@ + + + + + + EnvironmentId + {a05fc9db-6c77-45e7-9770-7cd31ad1131c} + + + ProjectExplorer.Project.ActiveTarget + 1 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.4.0 MinGW 32bit + Desktop Qt 5.4.0 MinGW 32bit + qt.54.win32_mingw491_kit + 0 + 0 + 0 + + C:/source/build-aesclass-Desktop_Qt_5_4_0_MinGW_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/source/build-aesclass-Desktop_Qt_5_4_0_MinGW_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + aesclass + + Qt4ProjectManager.Qt4RunConfiguration:C:/source/aesclass/aesclass.pro + + aesclass.pro + false + true + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop Qt 5.4.0 MSVC2013 32bit + Desktop Qt 5.4.0 MSVC2013 32bit + {41ee5de3-e0c6-4932-89be-818ac7411cf5} + 0 + 0 + 0 + + C:/source/build-aesclass-Desktop_Qt_5_4_0_MSVC2013_32bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/source/build-aesclass-Desktop_Qt_5_4_0_MSVC2013_32bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + aesclass + + Qt4ProjectManager.Qt4RunConfiguration:C:/source/aesclass/aesclass.pro + + aesclass.pro + false + true + + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.2 + + Desktop Qt 5.4.1 MSVC2013 64bit + Desktop Qt 5.4.1 MSVC2013 64bit + {481b3484-407d-4ae0-ba41-458f5e9d2bf2} + 0 + 0 + 0 + + C:/source/build-aesclass-Desktop_Qt_5_4_1_MSVC2013_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/source/build-aesclass-Desktop_Qt_5_4_1_MSVC2013_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + false + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.Target.3 + + Desktop Qt 5.4.0 MSVC2013 64bit + Desktop Qt 5.4.0 MSVC2013 64bit + {4a73e1a8-867f-4a8f-a70a-a3bb186185e4} + 0 + 0 + 0 + + C:/source/build-aesclass-Desktop_Qt_5_4_0_MSVC2013_64bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/source/build-aesclass-Desktop_Qt_5_4_0_MSVC2013_64bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy locally + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + -1 + + + + false + %{buildDir} + Custom Executable + + ProjectExplorer.CustomExecutableRunConfiguration + 3768 + false + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 4 + + + ProjectExplorer.Project.Updater.FileVersion + 18 + + + Version + 18 + + diff --git a/sfilterprocess/sfilterprocess.pro.user b/sfilterprocess/sfilterprocess.pro.user index 35c231a..377f68c 100644 --- a/sfilterprocess/sfilterprocess.pro.user +++ b/sfilterprocess/sfilterprocess.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -787,7 +787,7 @@ sfilterprocess Qt4ProjectManager.Qt4RunConfiguration:C:/source/sfilterprocess/sfilterprocess.pro - "465" "test2y" + "470" "test2y" sfilterprocess.pro false true