diff options
Diffstat (limited to 'IOFileClass/FileManIOFile.cpp')
| -rw-r--r-- | IOFileClass/FileManIOFile.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/IOFileClass/FileManIOFile.cpp b/IOFileClass/FileManIOFile.cpp index d0ae1f2..bee2ebe 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; } 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; @@ -66,12 +68,39 @@ void FileManIOFile::read(std::string key){ } -void FileManIOFile::write(std::string key, std::string data){ + + + +void FileManIOFile::write(std::string key,std::string data){ AESCrypt aes; + std::string dataEncrypted; + + dataEncrypted=aes.encrypt(key, data); + + this->writeRoutine(data, dataEncrypted); + + +} + +void FileManIOFile::write(std::string data){ + if(not(this->readable)){ + std::cout << "Can't write data without key (read it before) !" << std::endl; + std::exit(EXIT_FAILURE); + } + AESCrypt aes; + std::string dataEncrypted; + + dataEncrypted=aes.encrypt(this->key, data); + this->writeRoutine(data, dataEncrypted); + + +} + + +void FileManIOFile::writeRoutine(std::string data, std::string dataEncrypted){ HASHCrypt hash; - std::string dataEncrypted=aes.encrypt(key, data); byte digest[16]; hash.getMD5_128(data, digest, sizeof(digest)); @@ -89,10 +118,10 @@ void FileManIOFile::write(std::string key, std::string data){ file.close(); this->data=data; - } + std::string FileManIOFile::getData(){ return this->data; } |
