17 inline static const std::string BEGIN_RSA_PRIVATE_KEY_HEADER =
"-----BEGIN RSA PRIVATE KEY-----\n";
18 inline static const std::string END_RSA_PRIVATE_KEY_FOOTER =
"-----END RSA PRIVATE KEY-----\n";
19 inline static const std::string BEGIN_RSA_PUBLIC_KEY_HEADER =
"-----BEGIN RSA PUBLIC KEY-----\n";
20 inline static const std::string END_RSA_PUBLIC_KEY_FOOTER =
"-----END RSA PUBLIC KEY-----\n";
30 std::size_t keySize{};
31 std::optional<std::string> privateKey{std::nullopt};
33 std::optional<fs::path> privateKeyFilename{std::nullopt};
41 std::vector<byte>
Encrypt(
const std::string& password,
const byte *buffer,
const std::size_t buffSize)
override;
42 std::vector<byte>
Encrypt(
const std::string& password,
const std::vector<byte>& buffer)
override;
43 std::vector<byte>
Decrypt(
const std::string& password,
const byte *cipher,
const std::size_t cipherSize)
override;
44 std::vector<byte>
Decrypt(
const std::string& password,
const std::vector<byte>& cipher)
override;
45 void Encrypt(
const std::string& password,
const fs::path& in_filename,
const fs::path& out_filename)
override;
46 void Decrypt(
const std::string& password,
const fs::path& in_filename,
const fs::path& out_filename)
override;
52 [[deprecated(
"Not implemented yet")]]
61 using namespace CryptoPP;
62 RSASS<PSS, SHA256>::Signer signer(*m_private_key);
65 size_t length = signer.MaxSignatureLength();
66 SecByteBlock signature(length);
74 signature.resize(length);
77 RSASS<PSS, SHA256>::Verifier verifier(*m_public_key);
80 bool result = verifier.VerifyMessage(message.data(),
81 message.size(), signature, signature.size());
87 void setPrivateKey(
const std::string& privateKey);
88 void setPublicKey(
const std::string& publicKey);
99 std::unique_ptr<CryptoPP::RSAES<CryptoPP::OAEP<CryptoPP::SHA256>>::Encryptor> m_rsa_encryptor;
100 std::unique_ptr<CryptoPP::RSAES<CryptoPP::OAEP<CryptoPP::SHA256>>::Decryptor> m_rsa_decryptor;
101 std::unique_ptr<CryptoPP::RSA::PrivateKey> m_private_key;
102 std::unique_ptr<CryptoPP::RSA::PublicKey> m_public_key;
103 std::unique_ptr<CryptoPP::InvertibleRSAFunction> m_params;
105 std::unique_ptr<RSASettings> m_settings{};
110 {2048,
"Secure for use at least until 2030."},
111 {3072,
"Secure for use beyond 2030."},
112 {4096,
"Secure for longer-term security needs."},
113 {8192,
"Very high security but very slow. Suitable for cases requiring extremely high security,\nthough it's rarely used in practice due to performance concerns."},
114 {16384,
"Almost never used due to extreme computational cost.\nThis key size will take about ~5 minutes to complete"},
115 {32768,
"Theoretical and impractical for most applications\ndue to excessive computational and storage requirements.\nThis key size will take a lot of time to complete"},
#define NS_ENIGMA_BEGIN
Enable/Disable Assertions.
Algorithm abstract class.
static std::unique_ptr< CryptoPP::AutoSeededRandomPool > m_auto_seeded_random_pool
std::size_t getMaximumBufferSize() const
std::vector< byte > Encrypt(const std::string &password, const std::vector< byte > &buffer) override
void Encrypt(const std::string &password, const fs::path &in_filename, const fs::path &out_filename) override
RSA(const Algorithm::Intent intent) noexcept
void Decrypt(const std::string &password, const fs::path &in_filename, const fs::path &out_filename) override
std::string getPublicKey() const
std::vector< byte > Decrypt(const std::string &password, const std::vector< byte > &cipher) override
bool SignAndVerify(const std::vector< byte > &message)
std::vector< byte > Encrypt(const std::string &password, const byte *buffer, const std::size_t buffSize) override
void setSettings(RSASettings &&settings)
static const std::map< std::size_t, std::string_view > RECOMMENDED_KEY_SIZES
Key, description.
std::vector< byte > Decrypt(const std::string &password, const byte *cipher, const std::size_t cipherSize) override
static std::size_t getMaximumBufferSizeFromKeySize(const std::size_t keySize)
std::string getPrivateKey() const