summaryrefslogtreecommitdiff
path: root/IOFileClass/FileManIOFile.cpp
diff options
context:
space:
mode:
authormanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-11 17:04:01 +0400
committermanzerbredes <loic.guegan_secondary@yahoo.fr>2015-03-11 17:04:01 +0400
commit5783bf5e104813c3e62c134fb6a0d2c619a31635 (patch)
tree7d8faee0df18db62f93d9b63592ceb7d93c7fd52 /IOFileClass/FileManIOFile.cpp
parente261782473194273bf29eb033419501d7baf61be (diff)
Add support to save without key after read file with the key.
Diffstat (limited to 'IOFileClass/FileManIOFile.cpp')
-rw-r--r--IOFileClass/FileManIOFile.cpp44
1 files changed, 36 insertions, 8 deletions
diff --git a/IOFileClass/FileManIOFile.cpp b/IOFileClass/FileManIOFile.cpp
index 78758f4..424d704 100644
--- a/IOFileClass/FileManIOFile.cpp
+++ b/IOFileClass/FileManIOFile.cpp
@@ -16,7 +16,7 @@ FileManIOFile::FileManIOFile(std::string filename){
this->filename=filename;
this->readable=false;
this->data="";
- this->key[0]=NULL;
+ this->key;
}
FileManIOFile::~FileManIOFile(){
}
@@ -68,18 +68,18 @@ 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;
HASHCrypt hash;
std::string dataEncrypted;
- if(this->key!=NULL){
- dataEncrypted=aes.encrypt(key, data);
- }
- else{
- dataEncrypted=aes.encrypt(this->key, data);
- }
+ dataEncrypted=aes.encrypt(key, data);
+
+
byte digest[16];
hash.getMD5_128(data, digest, sizeof(digest));
@@ -100,6 +100,34 @@ void FileManIOFile::write(std::string key, std::string data){
}
+void FileManIOFile::write(std::string data){
+
+ AESCrypt aes;
+ HASHCrypt hash;
+ std::string dataEncrypted;
+
+ dataEncrypted=aes.encrypt(this->key, data);
+
+
+ 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;
+
+}
std::string FileManIOFile::getData(){
return this->data;