diff options
| author | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-03-11 09:51:03 +0400 |
|---|---|---|
| committer | manzerbredes <loic.guegan_secondary@yahoo.fr> | 2015-03-11 09:51:03 +0400 |
| commit | 783197aaa13abbfb7757ecec912dfe9cb6e52c75 (patch) | |
| tree | 399f42e41babbcf697f21c30f4cabb1f121e6c34 /CryptClass | |
| parent | 998745fe45c89570bd1d02e0e60199fc535da89b (diff) | |
Implement FileManIOFileClass, general bug correction.
Diffstat (limited to 'CryptClass')
| -rw-r--r-- | CryptClass/AESCrypt.cpp | 11 | ||||
| -rw-r--r-- | CryptClass/AESCrypt.hpp | 10 | ||||
| -rw-r--r-- | CryptClass/AbstractSKA.hpp | 4 | ||||
| -rw-r--r-- | CryptClass/HASHCrypt.cpp | 11 | ||||
| -rw-r--r-- | CryptClass/HASHCrypt.hpp | 5 |
5 files changed, 31 insertions, 10 deletions
diff --git a/CryptClass/AESCrypt.cpp b/CryptClass/AESCrypt.cpp index 08f00f2..0222e9a 100644 --- a/CryptClass/AESCrypt.cpp +++ b/CryptClass/AESCrypt.cpp @@ -8,8 +8,12 @@ * */ +//----- class ----- #include "AESCrypt.hpp" + + + //Constructor AESCrypt::AESCrypt(){ this->hash=HASHCrypt(); //Init hash attribute @@ -20,6 +24,8 @@ AESCrypt::~AESCrypt(){ } + + //Encrypt string std::string AESCrypt::encrypt(std::string key, std::string data){ @@ -30,6 +36,7 @@ std::string AESCrypt::encrypt(std::string key, std::string data){ //Contain data encrypted std::string cipher; + //Use try, catch to be ensure no problems happening try{ //Create encoder to encrypt data @@ -56,6 +63,8 @@ std::string AESCrypt::encrypt(std::string key, std::string data){ } + + //Decrypt string std::string AESCrypt::decrypt(std::string key, std::string data){ @@ -78,7 +87,7 @@ std::string AESCrypt::decrypt(std::string key, std::string data){ CryptoPP::StringSource ss3( data, true, new CryptoPP::StreamTransformationFilter( decoder, new CryptoPP::StringSink( cipher ), - CryptoPP::StreamTransformationFilter::ZEROS_PADDING + CryptoPP::StreamTransformationFilter::NO_PADDING ) ); } diff --git a/CryptClass/AESCrypt.hpp b/CryptClass/AESCrypt.hpp index a8fa976..4a0845c 100644 --- a/CryptClass/AESCrypt.hpp +++ b/CryptClass/AESCrypt.hpp @@ -8,6 +8,9 @@ * */ +#ifndef __AESCrypt__ +#define __AESCrypt__ + //----- std ----- #include "AbstractSKA.hpp" #include "HASHCrypt.hpp" @@ -39,7 +42,7 @@ class AESCrypt : public AbstractSKA { /** * @brief Encrypt data with AES algorithm. * - * @param key : key to encrypt data + * @param key : key used to encrypt data * @param data : contain data to encrypt. * * @return string : correspond to crypted data @@ -58,8 +61,7 @@ class AESCrypt : public AbstractSKA { * * @return string : correspond to decrypted data * - * Decrypt data, and return them in a string. - * Padding is not removed. + * Decrypt data, and return them into a string. * */ virtual std::string decrypt(std::string key, std::string data); @@ -69,3 +71,5 @@ class AESCrypt : public AbstractSKA { }; + +#endif diff --git a/CryptClass/AbstractSKA.hpp b/CryptClass/AbstractSKA.hpp index de03b1b..ca7230b 100644 --- a/CryptClass/AbstractSKA.hpp +++ b/CryptClass/AbstractSKA.hpp @@ -7,6 +7,8 @@ * Specify which method the algorithm must be implement. * */ +#ifndef __AbstractSKA__ +#define __AbstractSKA__ #include <string> @@ -52,3 +54,5 @@ class AbstractSKA { */ virtual std::string decrypt(std::string key, std::string data) = 0; }; + +#endif diff --git a/CryptClass/HASHCrypt.cpp b/CryptClass/HASHCrypt.cpp index 11fc04c..cd0dab6 100644 --- a/CryptClass/HASHCrypt.cpp +++ b/CryptClass/HASHCrypt.cpp @@ -8,10 +8,13 @@ * */ - +//----- class ----- #include "HASHCrypt.hpp" + + + //Constructor HASHCrypt::HASHCrypt(){ } @@ -47,7 +50,7 @@ void HASHCrypt::getSHA_256(std::string chain, byte* digest, int size){ } - +//Check the size of the digest void HASHCrypt::checkDigestSize(int sizeRequired, int size){ try{ if(size !=sizeRequired){ @@ -61,7 +64,7 @@ void HASHCrypt::checkDigestSize(int sizeRequired, int size){ } } - +//Make the error std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){ std::ostringstream erreurStream; erreurStream << "Invalid digest size ! ("<< sizeRequired <<" bytes required and "<< size <<" given)"; @@ -69,6 +72,7 @@ std::string HASHCrypt::getInvalidDigestSizeError(int sizeRequired, int size){ } +//Compare 2 digest (same size) bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){ //Try is more safe @@ -91,6 +95,7 @@ bool HASHCrypt::compareDigest(byte* digest1, byte* digest2, int size){ return true; } + //Convert digest to string std::string HASHCrypt::digestToString(byte* digest, int size){ diff --git a/CryptClass/HASHCrypt.hpp b/CryptClass/HASHCrypt.hpp index b377fac..2c17d3d 100644 --- a/CryptClass/HASHCrypt.hpp +++ b/CryptClass/HASHCrypt.hpp @@ -28,7 +28,7 @@ * @brief Hashing class * @author manzerbredes * - * Class who handle hashing functions to a byte* parameter. + * Class who handle hashing functions on a byte* parameter. * HASHCrypt try to detect errors and throw exceptions. * HASHCrypt use crypto++ library. */ @@ -111,6 +111,7 @@ class HASHCrypt{ */ void checkDigestSize(int sizeRequired, int size); + /** * @brief Make and error message. * @@ -123,8 +124,6 @@ class HASHCrypt{ */ std::string getInvalidDigestSizeError(int sizeRequired, int size); - - }; #endif |
