-
-
Notifications
You must be signed in to change notification settings - Fork 661
/
Copy pathrsa.hpp
41 lines (31 loc) · 1.01 KB
/
rsa.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
/**
* Canary - A free and open-source MMORPG server emulator
* Copyright (©) 2019-2024 OpenTibiaBR <[email protected]>
* Repository: https://github.com/opentibiabr/canary
* License: https://github.com/opentibiabr/canary/blob/main/LICENSE
* Contributors: https://github.com/opentibiabr/canary/graphs/contributors
* Website: https://docs.opentibiabr.com/
*/
#pragma once
class Logger;
class RSA {
public:
RSA(Logger &logger);
~RSA();
// Singleton - ensures we don't accidentally copy it
RSA(RSA const &) = delete;
void operator=(RSA const &) = delete;
static RSA &getInstance();
void start();
void setKey(const char* pString, const char* qString, int base = 10);
void decrypt(char* msg) const;
std::string base64Decrypt(const std::string &input) const;
uint16_t decodeLength(char*&pos) const;
void readHexString(char*&pos, uint16_t length, std::string &output) const;
bool loadPEM(const std::string &filename);
private:
Logger &logger;
mpz_t n;
mpz_t d;
};
constexpr auto g_RSA = RSA::getInstance;