-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEncrypter.cpp
More file actions
49 lines (37 loc) · 1.05 KB
/
Copy pathEncrypter.cpp
File metadata and controls
49 lines (37 loc) · 1.05 KB
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
#include "Encrypter.h"
Encrypter::Encrypter(CryptProtocol *prot) : prot(prot) {}
void Encrypter::encryptFiles(vector<PlainFile> &inputFiles, const fs::path &outputFilePath = "")
{
cout << "encrypting files" << endl;
ofstream ofs;
istream is(nullptr);
ofs.open(outputFilePath, ios_base::binary);
for (auto &file : inputFiles)
prot->encrypt(file, ofs);
ofs.close();
cout << "files encrypted" << endl
<< endl;
}
vector<PlainFile> Encrypter::decryptFile(const fs::path &inputFilePath)
{
cout << "decrypting file:\t" << inputFilePath.filename() << endl;
ifstream ifs;
ifs.open(inputFilePath, ios::binary);
auto files = decryptFile(ifs);
ifs.close();
cout << "file decrypted" << endl << endl;
return files;
}
vector<PlainFile> Encrypter::decryptFile(istream &is)
{
ostream os(nullptr);
vector<PlainFile> files;
while (true)
{
auto file = prot->decrypt(is);
if (file.pStBuf == nullptr)
break;
files.push_back(file);
}
return files;
}