-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
111 lines (63 loc) · 3.06 KB
/
Main.cpp
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
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include "Cipher.h"
int main()
{
try {
using namespace encryption;
const std::string text("Sensitive information");
std::cout << "Text: " << text << "\n\n------\n" << std::endl;
std::cout << std::left;
// AES-256-CBC
{
const std::string key("3994160DCB240A39BA7B8B479B534DF551716BC21A66285937965C14FD7565B5"),
iv ("735DA18098E045F012E59B9BBA63DA69");
auto e_text = Cipher::encrypt(text, key, iv, Cipher::KeyLength::H_256);
auto print_e_text_info = [](const auto& e_text) {
if(!e_text) {
std::cout << "Empty" << std::endl;
return;
}
constexpr int width = 30;
std::cout << std::setw(width) << "[AES-256-CBC] Encrypted Text: " << e_text.get() << std::endl;
std::cout << std::setw(width) << "[AES-256-CBC] Key: " << e_text.get_key() << std::endl;
std::cout << std::setw(width) << "[AES-256-CBC] Key Length: " << static_cast<Cipher::KeyLengthBase>(e_text.get_key_length()) << " bits" << std::endl;
std::cout << std::setw(width) << "[AES-256-CBC] IV: " << e_text.get_iv() << std::endl;
std::cout << std::setw(width) << "[AES-256-CBC] Decrypted Text: " << Cipher::decrypt(e_text) << std::endl;
};
print_e_text_info(e_text);
auto a = std::move(e_text);
std::cout << "\nAfter moving it: ";
print_e_text_info(e_text);
}
std::cout << "\n------\n" << std::endl;
// RSA
{
srand(time(nullptr));
auto e_text = Cipher::encrypt(text);
// Cipher::encrypt(text, seed); can be used to call 'srand(seed)' if 'seed != 1'
auto print_e_text_info = [](const auto& e_text) {
if(!e_text) {
std::cout << "Empty" << std::endl;
return;
}
auto[e, n] = e_text.get_public_keys();
auto[d, p, q] = e_text.get_private_keys();
constexpr int width = 22;
std::cout << std::setw(width) << "[RSA] Encrypted Text: " << e_text.to_str() << std::endl;
std::cout << std::setw(width) << "[RSA] Public Keys: " << "E = " << e << ", N = " << n << std::endl;
std::cout << std::setw(width) << "[RSA] Private Keys: " << "D = " << d << ", P = " << p << ", Q = " << q << std::endl;
std::cout << std::setw(width) << "[RSA] Decrypted Text: " << Cipher::decrypt(e_text) << std::endl;
};
print_e_text_info(e_text);
auto a = std::move(e_text);
std::cout << "\nAfter moving it: ";
print_e_text_info(e_text);
}
}catch(const std::exception& e) {
std::cerr << "\n------\nError: " << e.what() << "\n------" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}