summaryrefslogtreecommitdiff
path: root/IOFileClass
diff options
context:
space:
mode:
Diffstat (limited to 'IOFileClass')
-rw-r--r--IOFileClass/FileManIOFile.cpp10
-rw-r--r--IOFileClass/FileManIOFile.hpp4
2 files changed, 12 insertions, 2 deletions
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
+