forked from freezer333/cppwebify-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (64 loc) · 2.58 KB
/
main.cpp
File metadata and controls
66 lines (64 loc) · 2.58 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <iostream>
#include <stdio.h>
#include "cryptolib.h"
using namespace std;
int main(int argc, char ** argv) {
// command:
if(argc > 3){
string cmd = argv[1];
string encrypt_type = argv[2];
if(cmd == "encrypt"){
string input_type = argc > 3 ? argv[3] : "";
if(input_type == "file"){
string file_input = argc > 4 ? argv[4] : "";
string file_output = argc > 5 ? argv[5] : "";
string public_key_file = argc > 6 ? argv[6] : "";
CryptoLib clib(encrypt_type);
//std::cout << "load key" << std::endl;
clib.loadKey("", public_key_file);
//std::cout << "encrypt file" << std::endl;
clib.encryptFile(file_input, file_output);
}else if(input_type=="text"){
string msg_input = argc > 4 ? argv[4] : "";
string public_key_file = argc > 5 ? argv[5] : "";
CryptoLib clib(encrypt_type);
//std::cout << "load key" << std::endl;
clib.loadKey("", public_key_file);
//std::cout << "encrypt key" << std::endl;
std::string output = clib.encryptText(msg_input);
std::cout << output << std::endl;
}
}if(cmd == "decrypt"){
string input_type = argc > 3 ? argv[3] : "";
if(input_type == "file"){
string file_input = argc > 4 ? argv[4] : "";
string file_output = argc > 5 ? argv[5] : "";
string private_key_file = argc > 6 ? argv[6] : "";
CryptoLib clib(encrypt_type);
clib.loadKey(private_key_file, "");
clib.decryptFile(file_input, file_output);
}else if(input_type=="text"){
string msg_input = argc > 4 ? argv[4] : "";
string private_key_file = argc > 5 ? argv[5] : "";
CryptoLib clib(encrypt_type);
clib.loadKey(private_key_file, "");
std::string output = clib.decryptText(msg_input);
std::cout << output << std::endl;
}
}else if(cmd == "genkey"){
string private_key_file = argc > 3 ? argv[3]: "";
string public_key_file = argc > 4 ? argv[4] : "";
CryptoLib clib(encrypt_type);
clib.genKey(private_key_file, public_key_file);
}
//main_ecc(argc, argv);
}
return 0;
}
void help(){
cout << "crypto encrypt [ecc|aes] file fileinput fileoutput [publickeyfile] " << endl;
cout << "crypto decrypt [ecc|aes] file fileinput fileoutput [privatekeyfile] " << endl;
cout << "crypto encrypt [ecc|aes] text message messageoutput [publickeyfile] " << endl;
cout << "crypto decrypt [ecc|aes] text messageoutput message [privatekeyfile] " << endl;
cout << "crypto genkey [ecc|aes] privatekeyFile publickeyFile " << endl;
}