forked from ph4r05/Whitebox-crypto-AES
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mymain.cpp
52 lines (49 loc) · 1.43 KB
/
mymain.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
#include <string>
#include <fstream>
#include "my_wbaes.h"
#define LOGD(...) do { (void)printf(__VA_ARGS__); printf("\n"); } while(0);
static std::string string_to_hex(const std::string& s) {
std::string res;
char buff[3];
for(char c : s) {
sprintf(buff, "%02X", c);
res += buff;
}
return res;
}
int main(int argc, const char * argv[]) {
LOGD("mymain");
MyWbAes wbaes;
LOGD("wbaes object created");
std::string aesInstFile = "/data/local/tmp/test_aes_wb/inst1";
std::ifstream infile(aesInstFile.c_str(), std::ifstream::ate | std::ios::binary);
if(infile) {
LOGD("AES instance size: %ld", (long)infile.tellg());
infile.close();
LOGD("Loading AES instance");
bool ret = wbaes.load(aesInstFile);
if(!ret) {
LOGD("Failed to load AES instance");
return -1;
}
LOGD("AES instance loaded!");
}
else {
LOGD("Creating AES instance");
std::string randKey = "1234567890123456";
bool ret = wbaes.create(aesInstFile, randKey);
if(!ret) {
LOGD("Failed to create AES instance");
return -1;
}
LOGD("AES instance created!");
}
LOGD("Encrypt/decrypt test!");
std::string data = "..my plaintext..";
LOGD("Plaintext text: %s", string_to_hex(data).c_str());
wbaes.encrypt(data);
LOGD("Encrypted text: %s", string_to_hex(data).c_str());
wbaes.decrypt(data);
LOGD("Decrypted text: %s", string_to_hex(data).c_str());
LOGD("Encrypt/decrypt test end");
}