From 34b47f8e08eff519f6c8372f2e4ce5b24267614c Mon Sep 17 00:00:00 2001 From: manzerbredes Date: Wed, 11 Mar 2015 17:21:24 +0400 Subject: Arrange FileManIOFile class --- IOFileClass/FileManIOFile.cpp | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'IOFileClass/FileManIOFile.cpp') diff --git a/IOFileClass/FileManIOFile.cpp b/IOFileClass/FileManIOFile.cpp index 424d704..bee2ebe 100644 --- a/IOFileClass/FileManIOFile.cpp +++ b/IOFileClass/FileManIOFile.cpp @@ -74,40 +74,32 @@ void FileManIOFile::read(std::string key){ void FileManIOFile::write(std::string key,std::string data){ AESCrypt aes; - HASHCrypt hash; std::string dataEncrypted; dataEncrypted=aes.encrypt(key, data); + this->writeRoutine(data, dataEncrypted); - byte digest[16]; - hash.getMD5_128(data, digest, sizeof(digest)); - - - std::ofstream file; - file.open(this->filename, std::ios::out | std::ios::binary); - - file.write((char *) digest,sizeof(digest)); - - - file.write(dataEncrypted.c_str(), dataEncrypted.size()); - - - - file.close(); - - this->data=data; } 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; - HASHCrypt hash; std::string dataEncrypted; dataEncrypted=aes.encrypt(this->key, data); + this->writeRoutine(data, dataEncrypted); + +} + + +void FileManIOFile::writeRoutine(std::string data, std::string dataEncrypted){ + HASHCrypt hash; byte digest[16]; hash.getMD5_128(data, digest, sizeof(digest)); @@ -126,9 +118,10 @@ void FileManIOFile::write(std::string data){ file.close(); this->data=data; - } + + std::string FileManIOFile::getData(){ return this->data; } -- cgit v1.2.3