summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-11 16:47:05 +0400
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-11 16:47:05 +0400
commite261782473194273bf29eb033419501d7baf61be (patch)
treec203598d20746de24f1a635293f2b2ceea86af48
parent0b16b8eb9ae5e183d9e5146b3fa268844d69a88b (diff)
Change AESCrypt to support mutiple key type (string and byte)
-rw-r--r--CryptClass/AESCrypt.cpp24
-rw-r--r--CryptClass/AESCrypt.hpp5
-rw-r--r--IOFileClass/FileManIOFile.cpp10
-rw-r--r--IOFileClass/FileManIOFile.hpp4
4 files changed, 40 insertions, 3 deletions
diff --git a/CryptClass/AESCrypt.cpp b/CryptClass/AESCrypt.cpp
index 0222e9a..0add260 100644
--- a/CryptClass/AESCrypt.cpp
+++ b/CryptClass/AESCrypt.cpp
@@ -33,6 +33,18 @@ std::string AESCrypt::encrypt(std::string key, std::string data){
byte digest[32];
hash.getSHA_256(key, digest, (int)sizeof(digest));
+ return encryptRoutine(data, digest, sizeof(digest));
+
+}
+//Encrypt string
+std::string AESCrypt::encrypt(byte* key, std::string data){
+
+ return encryptRoutine(data, key, 32);
+
+}
+
+
+std::string AESCrypt::encryptRoutine(std::string data, byte* digest, int size){
//Contain data encrypted
std::string cipher;
@@ -41,7 +53,7 @@ std::string AESCrypt::encrypt(std::string key, std::string data){
try{
//Create encoder to encrypt data
CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption encoder;
- encoder.SetKey( digest, sizeof(digest) );
+ encoder.SetKey( digest, size );
//Encrypt data with StreamTransformationFilter with NO PADDING
CryptoPP::StringSource ss1(data, true,
@@ -61,10 +73,20 @@ std::string AESCrypt::encrypt(std::string key, std::string data){
//return encrypted data
return cipher;
+
}
+
+
+
+
+
+
+
+
+
//Decrypt string
std::string AESCrypt::decrypt(std::string key, std::string data){
diff --git a/CryptClass/AESCrypt.hpp b/CryptClass/AESCrypt.hpp
index 455eed0..58642c1 100644
--- a/CryptClass/AESCrypt.hpp
+++ b/CryptClass/AESCrypt.hpp
@@ -67,6 +67,11 @@ class AESCrypt : public AbstractSKA {
*/
virtual std::string decrypt(std::string key, std::string data);
+ std::string encrypt(byte* key, std::string data);
+
+ std::string encryptRoutine(std::string data, byte* digest, int size);
+
+
private:
HASHCrypt hash; ///< hash instance to generate SHA-256 hash code.
diff --git a/IOFileClass/FileManIOFile.cpp b/IOFileClass/FileManIOFile.cpp
index d0ae1f2..78758f4 100644
--- a/IOFileClass/FileManIOFile.cpp
+++ b/IOFileClass/FileManIOFile.cpp
@@ -16,6 +16,7 @@ FileManIOFile::FileManIOFile(std::string filename){
this->filename=filename;
this->readable=false;
this->data="";
+ this->key[0]=NULL;
}
FileManIOFile::~FileManIOFile(){
}
@@ -55,6 +56,7 @@ void FileManIOFile::read(std::string key){
if(hash.compareDigest(fileMD5, currentMD5, sizeof(currentMD5))){
this->readable=true;
+ hash.getSHA_256(key, this->key, 32);
}
else{
this->readable=false;
@@ -70,8 +72,14 @@ void FileManIOFile::write(std::string key, std::string data){
AESCrypt aes;
HASHCrypt hash;
+ std::string dataEncrypted;
- std::string dataEncrypted=aes.encrypt(key, data);
+ if(this->key!=NULL){
+ dataEncrypted=aes.encrypt(key, data);
+ }
+ else{
+ dataEncrypted=aes.encrypt(this->key, data);
+ }
byte digest[16];
hash.getMD5_128(data, digest, sizeof(digest));
diff --git a/IOFileClass/FileManIOFile.hpp b/IOFileClass/FileManIOFile.hpp
index 4dfcfc4..fbed051 100644
--- a/IOFileClass/FileManIOFile.hpp
+++ b/IOFileClass/FileManIOFile.hpp
@@ -58,7 +58,7 @@ class FileManIOFile {
* Save data to "filename" attribute.
*
*/
- void write(std::string key, std::string data);
+ void write(std::string data,std::string key=NULL);
/**
* @brief True if file fully decrypted.
@@ -87,6 +87,8 @@ class FileManIOFile {
bool readable; ///< Readable attribute
+ byte key[32]; ///< Key in SHA-256
+