-
Notifications
You must be signed in to change notification settings - Fork 0
/
RSA.h
55 lines (42 loc) · 917 Bytes
/
RSA.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
#ifndef _RSA_H_
#define _RSA_H_
#include <NTL/ZZ.h>
#include <cstring>
using namespace NTL;
const unsigned char HexTable[] = "0123456789ABCDEF";
const std::string Base64Map =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";
struct PublicKey {
ZZ n, b;
};
struct PrivateKey {
ZZ p, q, a;
};
struct Message {
ZZ c1;
ZZ IV;
std::string fileName;
};
class RSAUser {
public:
RSAUser();
void GenerateKey();
void SendPublicKey(RSAUser&);
void SendMessage(RSAUser&);
void EncryptMessage();
void DecryptMessage();
PublicKey pk;
Message M;
private:
void createTempKey();
void viewKey(const size_t);
void printKey(ZZ, const size_t);
void PrintInPEM(const std::string);
void PrintInDER(const std::string);
std::string ZZToBits(ZZ, const size_t);
PrivateKey sk;
ZZ k; // 临时会话密钥
};
#endif