This is a simulation/stub implementation. Generated keys are dummy bytes (zero-filled), not real cryptographic material. Do not use in production security contexts.
Data types
KeyType enum
Identifies the algorithm associated with a stored key.
| Value | Description |
|---|---|
KeyType::RSA | RSA asymmetric key |
KeyType::AES | AES symmetric key |
Key struct
Unique identifier for the key, e.g.
"RSA_2048" or "AES_256".Algorithm type:
KeyType::RSA or KeyType::AES.Raw key bytes. In this stub implementation, always zero-filled with length equal to
bits / 8.Methods
void init()
Initializes the HSM instance. Prints "HSM initialized" to standard output. Must be called before any other method.
Parameters: None
Returns: void
std::string generate_rsa_key(int bits = 2048)
Generates a stub RSA key entry and stores it in the internal key map.
Key size in bits. Controls the length of the zero-filled dummy byte vector stored (
bits / 8 bytes).std::string — the key ID in the format "RSA_<bits>", e.g. "RSA_2048".
std::string generate_aes_key(int bits = 256)
Generates a stub AES key entry and stores it in the internal key map.
Key size in bits. Controls the length of the zero-filled dummy byte vector stored (
bits / 8 bytes). Common values: 128, 192, 256.std::string — the key ID in the format "AES_<bits>", e.g. "AES_256".
Key get_key(const std::string& id)
Retrieves a previously generated key by its ID.
The key ID returned by
generate_rsa_key() or generate_aes_key(), e.g. "RSA_2048".Key — the matching Key struct. Returns an empty default-constructed Key{} (empty id, empty data) if the ID is not found.
std::vector<uint8_t> get_random_bytes(size_t length)
Generates cryptographically seeded random bytes using std::random_device.
Number of random bytes to generate.
std::vector<uint8_t> — a vector of length random bytes.