-
Notifications
You must be signed in to change notification settings - Fork 1
/
Keys.hpp
54 lines (46 loc) · 1.7 KB
/
Keys.hpp
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
#pragma once
// TODO:: Refractor this module
#include <cryptopp/aes.h>
#include <cryptopp/base64.h>
#include <cryptopp/osrng.h>
#include <cryptopp/rsa.h>
#include <memory>
#include <string>
class Base64Wrapper
{
public:
static std::string encode(const std::string &str);
static std::string decode(const std::string &str);
private:
static std::string base64_encode(const unsigned char *buffer,
size_t length);
};
class RSAPrivateWrapper
{
public:
static const unsigned int BITS = 1024;
RSAPrivateWrapper();
RSAPrivateWrapper(const std::string &public_key,
const std::string &private_key);
RSAPrivateWrapper(const char *key, unsigned int length);
explicit RSAPrivateWrapper(const std::string &key);
~RSAPrivateWrapper();
std::string getPublicKeyString() const;
std::string getPrivateKeyString() const;
void loadPrivateKey(const std::string &key);
void loadPublicKey(const std::string &key);
std::string getPrivateKey() const;
char *getPrivateKey(char *keyout, unsigned int length) const;
std::string getPublicKey() const;
char *getPublicKey(char *keyout, unsigned int length) const;
std::string decrypt(const std::string &cipher);
std::string decrypt(const char *cipher, unsigned int length);
private:
std::string public_key_;
std::string private_key_; // stored in priv.key file
std::unique_ptr<CryptoPP::AutoSeededRandomPool> _rng;
std::unique_ptr<CryptoPP::RSA::PrivateKey> _privateKey;
// Disallow copy and assignment
RSAPrivateWrapper(const RSAPrivateWrapper &rsaprivate) = delete;
RSAPrivateWrapper &operator=(const RSAPrivateWrapper &rsaprivate) = delete;
};