Add RSA keypair generation and signing implementation for Overte authentication

This commit is contained in:
MayaTheShy
2025-11-16 19:45:17 -05:00
parent 1ed1ad2a28
commit c2fec07ad6
2 changed files with 164 additions and 0 deletions

32
src/RSAKeypair.hpp Normal file
View File

@@ -0,0 +1,32 @@
// RSAKeypair.hpp - RSA keypair generation and signing for Overte authentication
#pragma once
#include <vector>
#include <string>
#include <cstdint>
class RSAKeypair {
public:
RSAKeypair();
~RSAKeypair();
// Generate a new 2048-bit RSA keypair
bool generate();
// Sign plaintext with SHA256 + RSA
std::vector<uint8_t> sign(const std::vector<uint8_t>& plaintext) const;
// Get DER-encoded keys
std::vector<uint8_t> getPublicKeyDER() const { return m_publicKey; }
std::vector<uint8_t> getPrivateKeyDER() const { return m_privateKey; }
// Set keys from DER encoding (for loading from file)
void setKeys(const std::vector<uint8_t>& publicKey, const std::vector<uint8_t>& privateKey);
// Check if keypair is valid
bool isValid() const { return !m_privateKey.empty() && !m_publicKey.empty(); }
private:
std::vector<uint8_t> m_publicKey;
std::vector<uint8_t> m_privateKey;
};