Async 1.8.0
Async::SslKeypair Class Reference

A class representing private and public keys. More...

#include <AsyncSslKeypair.h>

Public Member Functions

 SslKeypair (void)
 Default constructor.
 
 SslKeypair (EVP_PKEY *pkey)
 Constructor.
 
 SslKeypair (SslKeypair &&other)
 Move constructor.
 
 SslKeypair (SslKeypair &other)
 Copy constructor.
 
SslKeypairoperator= (SslKeypair &other)
 Copy assignment operator.
 
 ~SslKeypair (void)
 Destructor.
 
bool isNull (void) const
 Check if the object is empty.
 
bool generate (unsigned int bits)
 Generate a new RSA keypair.
 
template<class T >
bool newRawPrivateKey (int type, const T &key)
 Generate a key using the given algorithm and raw key data.
 
std::string privateKeyPem (void) const
 Return the private key on PEM form.
 
bool privateKeyFromPem (const std::string &pem)
 Create key from the given PEM data.
 
bool writePrivateKeyFile (const std::string &filename)
 Write key data to file on PEM format.
 
bool readPrivateKeyFile (const std::string &filename)
 Read key data from PEM file.
 
std::string publicKeyPem (void) const
 Get the public key on PEM form.
 
bool publicKeyFromPem (const std::string &pem)
 Create public key from PEM string.
 
 operator EVP_PKEY * (void)
 Cast to pointer to EVP_PKEY.
 
 operator const EVP_PKEY * (void) const
 
bool operator!= (const SslKeypair &other) const
 Check if two keys is not equal to each other.
 

Detailed Description

A class representing private and public keys.

Author
Tobias Blomberg / SM0SVX
Date
2024-07-11
Examples
AsyncDigest_demo.cpp, and AsyncSslX509_demo.cpp.

Definition at line 123 of file AsyncSslKeypair.h.

Constructor & Destructor Documentation

◆ SslKeypair() [1/4]

Async::SslKeypair::SslKeypair ( void )
inline

Default constructor.

Definition at line 129 of file AsyncSslKeypair.h.

◆ SslKeypair() [2/4]

Async::SslKeypair::SslKeypair ( EVP_PKEY * pkey)
inlineexplicit

Constructor.

Parameters
pkeyA pointer to an existing EVP_PKEY object

Definition at line 135 of file AsyncSslKeypair.h.

◆ SslKeypair() [3/4]

Async::SslKeypair::SslKeypair ( SslKeypair && other)
inline

Move constructor.

Parameters
otherThe object to move from

Definition at line 144 of file AsyncSslKeypair.h.

◆ SslKeypair() [4/4]

Async::SslKeypair::SslKeypair ( SslKeypair & other)
inline

Copy constructor.

Parameters
otherThe other object to copy

Definition at line 154 of file AsyncSslKeypair.h.

◆ ~SslKeypair()

Async::SslKeypair::~SslKeypair ( void )
inline

Destructor.

Definition at line 175 of file AsyncSslKeypair.h.

Member Function Documentation

◆ generate()

bool Async::SslKeypair::generate ( unsigned int bits)
inline

Generate a new RSA keypair.

Parameters
bitsModulus size in number of bits
Returns
Returns true on success
Examples
AsyncSslX509_demo.cpp.

Definition at line 192 of file AsyncSslKeypair.h.

◆ isNull()

bool Async::SslKeypair::isNull ( void ) const
inline

Check if the object is empty.

Returns
Returns true if the object is empty/uninitialized

Definition at line 185 of file AsyncSslKeypair.h.

Referenced by Async::Digest::signVerifyInit().

◆ newRawPrivateKey()

template<class T >
bool Async::SslKeypair::newRawPrivateKey ( int type,
const T & key )
inline

Generate a key using the given algorithm and raw key data.

Parameters
typeThe algorithm to use
keyThe raw key data
Returns
Returns true on success

To fully understand what this function do, read the documentation for the OpenSSL function EVP_PKEY_new_raw_private_key.

Ex: newRawPrivateKey(EVP_PKEY_HMAC, key);

Definition at line 264 of file AsyncSslKeypair.h.

◆ operator const EVP_PKEY *()

Async::SslKeypair::operator const EVP_PKEY * ( void ) const
inline

Definition at line 440 of file AsyncSslKeypair.h.

◆ operator EVP_PKEY *()

Async::SslKeypair::operator EVP_PKEY * ( void )
inline

Cast to pointer to EVP_PKEY.

Returns
Returns a pointer to the internal EVP_PKEY object

Definition at line 439 of file AsyncSslKeypair.h.

◆ operator!=()

bool Async::SslKeypair::operator!= ( const SslKeypair & other) const
inline

Check if two keys is not equal to each other.

Parameters
otherThe other key to use in the comparison
Returns
Returns true if the keys are not the same

Definition at line 447 of file AsyncSslKeypair.h.

◆ operator=()

SslKeypair & Async::SslKeypair::operator= ( SslKeypair & other)
inline

Copy assignment operator.

Parameters
otherThe object to copy from
Returns
Returns a reference to this object

Definition at line 165 of file AsyncSslKeypair.h.

◆ privateKeyFromPem()

bool Async::SslKeypair::privateKeyFromPem ( const std::string & pem)
inline

Create key from the given PEM data.

Parameters
pemA sting containing PEM data
Returns
Returns true on success
Examples
AsyncDigest_demo.cpp.

Definition at line 312 of file AsyncSslKeypair.h.

◆ privateKeyPem()

std::string Async::SslKeypair::privateKeyPem ( void ) const
inline

Return the private key on PEM form.

Returns
Returns a sting containing PEM data
Examples
AsyncDigest_demo.cpp.

Definition at line 281 of file AsyncSslKeypair.h.

◆ publicKeyFromPem()

bool Async::SslKeypair::publicKeyFromPem ( const std::string & pem)
inline

Create public key from PEM string.

Parameters
pemA string containing PEM data
Returns
Returns true on success
Examples
AsyncDigest_demo.cpp.

Definition at line 417 of file AsyncSslKeypair.h.

◆ publicKeyPem()

std::string Async::SslKeypair::publicKeyPem ( void ) const
inline

Get the public key on PEM form.

Returns
Returns a string containing PEM data
Examples
AsyncDigest_demo.cpp.

Definition at line 394 of file AsyncSslKeypair.h.

◆ readPrivateKeyFile()

bool Async::SslKeypair::readPrivateKeyFile ( const std::string & filename)
inline

Read key data from PEM file.

Parameters
filenameThe path to the file to read PEM data from
Returns
Returns true on success

Definition at line 368 of file AsyncSslKeypair.h.

◆ writePrivateKeyFile()

bool Async::SslKeypair::writePrivateKeyFile ( const std::string & filename)
inline

Write key data to file on PEM format.

Parameters
filenameThe path to the file to write
Returns
Returns \rm true on success
Examples
AsyncSslX509_demo.cpp.

Definition at line 330 of file AsyncSslKeypair.h.


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