C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
essence::crypto::asymmetric_key Class Reference

Represents an asymmetric key or key pair for a pubkey encryption algorithm. More...

#include <asymmetric_key.hpp>

Public Member Functions

 ES_API (CPPESSENCE) explicit asymmetric_key(void *blob)
 Creates an instance from an internal blob.
 
 asymmetric_key (use_public_tag tag, zstring_view path, const password_request_handler &handler={})
 Creates an instance from a public key stored on the disk.
 
 asymmetric_key (use_public_tag tag, std::span< const std::byte > buffer, const password_request_handler &handler={})
 Creates an instance from a memory buffer storing a public key.
 
 asymmetric_key (use_private_tag tag, zstring_view path, const password_request_handler &handler={})
 Creates an instance from a private key stored on the disk.
 
 asymmetric_key (use_private_tag tag, std::span< const std::byte > buffer, const password_request_handler &handler={})
 Creates an instance from a memory buffer storing a private key.
 
 ES_API (CPPESSENCE) asymmetric_key(asymmetric_key &&) noexcept
 
 ES_API (CPPESSENCE) ~asymmetric_key()
 
 ES_API (CPPESSENCE) asymmetric_key &operator
 
 ES_API (CPPESSENCE) asymmetric_key_type type() const
 Gets the type of the asymmetric key.
 
ES_API(CPPESSENCE) abi ES_API(CPPESSENCE) abi ES_API (CPPESSENCE) void *to_blob() const noexcept
 Gets the name of the asymmetric key.
 
ES_API(CPPESSENCE) abi ES_API (CPPESSENCE) void save_public(zstring_view path) const
 Saves the public key to a string.
 
ES_API(CPPESSENCE) abi ES_API(CPPESSENCE) abi ES_API (CPPESSENCE) void save_private(zstring_view path) const
 Saves the private key to a string.
 
void save_private (zstring_view path, zstring_view cipher_name, std::string_view password) const
 Encrypts and saves the private key to a file.
 

Detailed Description

Represents an asymmetric key or key pair for a pubkey encryption algorithm.

See also
pubkey_cipher_provider

Constructor & Destructor Documentation

◆ asymmetric_key() [1/4]

essence::crypto::asymmetric_key::asymmetric_key ( use_public_tag tag,
zstring_view path,
const password_request_handler & handler = {} )

Creates an instance from a public key stored on the disk.

Parameters
tagThe hint tag for overloading, should always be essence::crypto::use_public.
pathThe path of the public key file.
handlerAn optional callable object to retrieve the password having encrypted the key.
See also
password_request_handler

◆ asymmetric_key() [2/4]

essence::crypto::asymmetric_key::asymmetric_key ( use_public_tag tag,
std::span< const std::byte > buffer,
const password_request_handler & handler = {} )

Creates an instance from a memory buffer storing a public key.

Parameters
tagthe hint tag for overloading, should always be essence::crypto::use_public.
bufferthe memory buffer containing the public key.
handleran optional callable object to retrieve the password having encrypted the key.

◆ asymmetric_key() [3/4]

essence::crypto::asymmetric_key::asymmetric_key ( use_private_tag tag,
zstring_view path,
const password_request_handler & handler = {} )

Creates an instance from a private key stored on the disk.

Parameters
tagThe hint tag for overloading, should always be essence::crypto::use_private.
pathThe path of the private key file.
handlerAn optional callable object to retrieve the password having encrypted the key.
See also
password_request_handler

◆ asymmetric_key() [4/4]

essence::crypto::asymmetric_key::asymmetric_key ( use_private_tag tag,
std::span< const std::byte > buffer,
const password_request_handler & handler = {} )

Creates an instance from a memory buffer storing a private key.

Parameters
tagThe hint tag for overloading, should always be essence::crypto::use_private.
bufferThe memory buffer containing the private key.
handlerAn optional callable object to retrieve the password having encrypted the key.

Member Function Documentation

◆ ES_API() [1/5]

essence::crypto::asymmetric_key::ES_API ( CPPESSENCE ) const
nodiscard

Gets the type of the asymmetric key.

Returns
The type of the asymmetric key.
See also
asymmetric_key_type

◆ ES_API() [2/5]

essence::crypto::asymmetric_key::ES_API ( CPPESSENCE )

Creates an instance from an internal blob.

Warning
DO NOT USE this constructor unless you know what you are doing.
Parameters
bloba pointer to the internal blob.

◆ ES_API() [3/5]

ES_API(CPPESSENCE) abi ES_API(CPPESSENCE) abi essence::crypto::asymmetric_key::ES_API ( CPPESSENCE ) const
nodiscardnoexcept

Gets the name of the asymmetric key.

Returns
The name of the asymmetric key.

Gets the description of the asymmetric key.

Returns
The description of the asymmetric key.

Gets the internal blob.

Returns
The internal blob.

◆ ES_API() [4/5]

ES_API(CPPESSENCE) abi ES_API(CPPESSENCE) abi essence::crypto::asymmetric_key::ES_API ( CPPESSENCE ) const
nodiscard

Saves the private key to a string.

Returns
The string containing the private key.

Encrypts and saves the private key to a string.

Parameters
cipher_nameThe name of a symmetric cipher to encrypt the key.
passwordThe password coded in displayable characters to encrypt the key.
Returns
The string containing the encrypted private key.

Saves the private key to a file.

Parameters
pathThe path of the file.

◆ ES_API() [5/5]

ES_API(CPPESSENCE) abi essence::crypto::asymmetric_key::ES_API ( CPPESSENCE ) const
nodiscard

Saves the public key to a string.

Returns
The string containing the public key.

Saves the public key to a file.

Parameters
pathThe path of the file.

◆ save_private()

void essence::crypto::asymmetric_key::save_private ( zstring_view path,
zstring_view cipher_name,
std::string_view password ) const

Encrypts and saves the private key to a file.

Parameters
pathThe path of the file.
cipher_nameThe name of a symmetric cipher to encrypt the key.
passwordThe password coded in displayable characters to encrypt the key.

The documentation for this class was generated from the following file: