-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileReader.h
76 lines (62 loc) · 2.07 KB
/
FileReader.h
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
//==================================================================================
// Name : FileReader.h
// Author : Julien Thibodeau
// Description : Declaration for FileReader.cpp in C++, Ansi-style
//==================================================================================
#include <fstream>
#include <stdexcept>
#include <string>
#include <vector>
#include <unistd.h>
#include <experimental/filesystem>
#include <iostream>
#include <sys/stat.h>
#include "cryptopp/modes.h"
#include "cryptopp/aes.h"
#include "cryptopp/osrng.h"
#include "cryptopp/hex.h"
#include "cryptopp/hkdf.h"
#include "cryptopp/pssr.h"
#include <jsoncpp/json/json.h>
inline bool isFileExistReader(const std::string &name)
{
struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}
std::string getCurrentDirReader()
{
char buff[FILENAME_MAX];
getcwd(buff, FILENAME_MAX);
std::string currentWorkingDir(buff);
return currentWorkingDir;
}
struct SHA512keysReader
{
std::string key;
std::string iv;
};
struct DataInfosJsonRowReader
{
std::string url;
std::string user;
std::string pwd;
};
class FileReader
{
private:
inline static const std::string ivFile = "D04BF8250278335D017A5FE311151DE2";
inline static const std::string pathFile = getCurrentDirReader() + "/accounts.encrypted";
bool validateJsonContentData(std::string pwdFile);
std::string aesCTRDecrypt(std::string KEY, std::string IV, std::string infoToDecrypt);
std::string aesCBCDecrypt(std::string KEY, std::string IV, std::string infoToDecrypt);
std::string DecryptJsonFile(SHA512keysReader sha512keys);
SHA512keysReader generateKeyIv(std::string pwdContent);
SHA512keysReader generateKeyFromPwdAndIv(std::string pwdContent, std::string encodedIv);
public:
FileReader();
~FileReader();
bool validatepwdFile(std::string pwdFile);
bool validatepwdContent(std::string pwdFile, std::string pwdContent);
int printListEntriesInfosCensored(std::string pwdFile);
void printListEntriesInfosDecrypted(std::string pwdFile, std::string pwdContent);
};