Implement FileManIOFileClass, general bug correction.

This commit is contained in:
manzerbredes 2015-03-11 09:51:03 +04:00
parent 998745fe45
commit 783197aaa1
8 changed files with 228 additions and 18 deletions

View file

@ -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
)
);
}

View file

@ -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

View file

@ -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

View file

@ -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){

View file

@ -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