blob: 7013b27d67791ec4fdd17ef3db10121881584bae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/**
* @file FileManIOFile.hpp
* @brief FileManIOFile class definitions
* @author manzerbredes
* @date 9 Mars 2015
*
* Contain all definitions of FileManIOFile class.
*
*/
#ifndef __FileManIOFile__
#define __FileManIOFile__
//--- std -----
#include <iostream>
#include <string>
#include <fstream>
//----- class -----
#include "HASHCrypt.hpp"
#include "AESCrypt.hpp"
/**
* @class FileManIOFile FileManIOFile.hpp "/CryptClass/FileManIOFile.hpp"
* @brief Class for quick open and close encrypted file.
* @author manzerbredes
*
* -----File organisation-----
*
* 16 first bytes : md5 of decrypted file
* rest of the file : data encrypted (ASE for now)
*
*/
class FileManIOFile {
public:
FileManIOFile(std::string filename);
~FileManIOFile();
/**
* @brief Read encrypted file.
*
* @param key : key to encrypt data
*
* Read data from "filename" attribute.
* If file fully decrypted, readable var switch to true.
*
*/
void read(std::string key);
/**
* @brief Write data in encrypted file.
*
* @param key : key to encrypt data
* @param data : data to write
*
* Write the file with or without key
* To write data without key, you need to read it before (to save the key
* in attribute key;
*
*/
void write(std::string key, std::string data);
void write(std::string data);
/**
* @brief Write data in encrypted file.
*
* @param data : data to write (for MD5)
* @param dataEncrypted : data to write
*
* Write encryptedData to filename
*
*/
void writeRoutine(std::string data, std::string dataEncrypted);
/**
* @brief True if file fully decrypted.
*
* Return "readable" attribute.
*
*/
bool isReadable();
/**
* @brief Get data attribute.
*
* Return "data" attribute.
*
* **Warning** if data not fully decrypted (readable!=true),
* data will be unreadable.
*/
std::string getData();
private:
std::string filename; ///< Filename attribute
std::string data; ///< Data attribute
bool readable; ///< Readable attribute
byte key[32]; ///< Key in SHA-256
};
#endif
|