A class representing a public/private key pair.
More...
#include <keypair.hxx>
|
| KeyPair (const std::string &pub, const std::string &priv) noexcept |
| Constructs a KeyPair with a public and private key.
|
|
| KeyPair (const std::string &pub) noexcept |
| Constructs a KeyPair with a public key only.
|
|
| KeyPair (std::string &&pub, std::string &&priv) noexcept |
| Constructs a KeyPair with a public and private key (move version).
|
|
| KeyPair (std::string &&pub) noexcept |
| Constructs a KeyPair with a public key only (move version).
|
|
| KeyPair (const KeyPair &other)=default |
| Copy constructor.
|
|
| KeyPair (KeyPair &&other) noexcept=default |
| Move constructor.
|
|
| ~KeyPair () noexcept=default |
| Destructor.
|
|
KeyPair & | operator= (const KeyPair &other)=default |
| Copy assignment operator.
|
|
KeyPair & | operator= (KeyPair &&other) noexcept=default |
| Move assignment operator.
|
|
const std::string & | PublicKey () const noexcept |
| Returns the public key.
|
|
const std::optional< std::string > & | PrivateKey () const noexcept |
| Returns the private key.
|
|
|
static Expected< KeyPair, Exception > | Generate (const Algorithm::Asymmetric &algo, const size_t &key_size) noexcept |
| Generates a random key pair using the specified algorithm and key size.
|
|
static Expected< KeyPair, Exception > | Generate (const Algorithm::Asymmetric &algo, const std::string &curve_name) noexcept |
| Generates a random key pair using the specified algorithm and curve name.
|
|
static Expected< KeyPair, Exception > | Generate (const Algorithm::Sign &algo, const size_t &key_size) noexcept |
| Generates a random key pair for signing using the specified algorithm and key size.
|
|
static Expected< KeyPair, Exception > | Generate (const Algorithm::Sign &algo, const std::string &curve_name) noexcept |
| Generates a random key pair for signing using the specified algorithm and curve name.
|
|
static Expected< KeyPair, Exception > | Generate (const Algorithm::SecretShare &algo, const std::string &curve_name) noexcept |
| Generates a random key pair for secret-sharing using the specified algorithm and curve name.
|
|
A class representing a public/private key pair.
A KeyPair
can contain both a public key and a private key, or only a public key.
- If only the public key is provided, the
KeyPair
can be used for encryption and signature verification.
- If both the public and private keys are provided, the
KeyPair
can also be used for decryption and signing.
◆ KeyPair() [1/6]
StormByte::Crypto::KeyPair::KeyPair |
( |
const std::string & |
pub, |
|
|
const std::string & |
priv |
|
) |
| |
|
noexcept |
Constructs a KeyPair with a public and private key.
This constructor creates a KeyPair
that can be used for all cryptographic operations, including encryption, decryption, signing, and signature verification.
- Parameters
-
pub | The public key. |
priv | The private key. |
◆ KeyPair() [2/6]
StormByte::Crypto::KeyPair::KeyPair |
( |
const std::string & |
pub | ) |
|
|
noexcept |
Constructs a KeyPair with a public key only.
This constructor creates a KeyPair
that can only be used for encryption and signature verification. Decryption and signing operations will not be available because the private key is not provided.
- Parameters
-
◆ KeyPair() [3/6]
StormByte::Crypto::KeyPair::KeyPair |
( |
std::string && |
pub, |
|
|
std::string && |
priv |
|
) |
| |
|
noexcept |
Constructs a KeyPair with a public and private key (move version).
This constructor moves the public and private keys into the KeyPair
instance.
- Parameters
-
pub | The public key (rvalue reference). |
priv | The private key (rvalue reference). |
◆ KeyPair() [4/6]
StormByte::Crypto::KeyPair::KeyPair |
( |
std::string && |
pub | ) |
|
|
noexcept |
Constructs a KeyPair with a public key only (move version).
This constructor moves the public key into the KeyPair
instance. Decryption and signing operations will not be available because the private key is not provided.
- Parameters
-
pub | The public key (rvalue reference). |
◆ KeyPair() [5/6]
StormByte::Crypto::KeyPair::KeyPair |
( |
const KeyPair & |
other | ) |
|
|
default |
Copy constructor.
Creates a copy of the given KeyPair
instance.
- Parameters
-
◆ KeyPair() [6/6]
StormByte::Crypto::KeyPair::KeyPair |
( |
KeyPair && |
other | ) |
|
|
defaultnoexcept |
Move constructor.
Moves the given KeyPair
instance into the current instance.
- Parameters
-
◆ ~KeyPair()
StormByte::Crypto::KeyPair::~KeyPair |
( |
| ) |
|
|
defaultnoexcept |
Destructor.
Cleans up the KeyPair
instance. This includes releasing any resources associated with the public and private keys.
◆ Generate() [1/5]
static Expected< KeyPair, Exception > StormByte::Crypto::KeyPair::Generate |
( |
const Algorithm::Asymmetric & |
algo, |
|
|
const size_t & |
key_size |
|
) |
| |
|
staticnoexcept |
Generates a random key pair using the specified algorithm and key size.
This method generates both a public and private key, creating a KeyPair
that can be used for all cryptographic operations.
- Parameters
-
algo | The algorithm to use for key generation. |
key_size | The size of the key to generate. |
- Returns
- An Expected containing the generated KeyPair or an error.
◆ Generate() [2/5]
static Expected< KeyPair, Exception > StormByte::Crypto::KeyPair::Generate |
( |
const Algorithm::Asymmetric & |
algo, |
|
|
const std::string & |
curve_name |
|
) |
| |
|
staticnoexcept |
Generates a random key pair using the specified algorithm and curve name.
This method generates both a public and private key, creating a KeyPair
that can be used for all cryptographic operations.
- Parameters
-
algo | The algorithm to use for key generation. |
curve_name | The name of the elliptic curve (e.g., "secp256r1"). |
- Returns
- An Expected containing the generated KeyPair or an error.
◆ Generate() [3/5]
static Expected< KeyPair, Exception > StormByte::Crypto::KeyPair::Generate |
( |
const Algorithm::SecretShare & |
algo, |
|
|
const std::string & |
curve_name |
|
) |
| |
|
staticnoexcept |
Generates a random key pair for secret-sharing using the specified algorithm and curve name.
This method generates both a public and private key, creating a KeyPair
that can be used for shared secret generation.
- Parameters
-
algo | The secret-sharing algorithm to use. |
curve_name | The name of the elliptic curve (e.g., "secp256r1"). |
- Returns
- An Expected containing the generated KeyPair or an error.
◆ Generate() [4/5]
static Expected< KeyPair, Exception > StormByte::Crypto::KeyPair::Generate |
( |
const Algorithm::Sign & |
algo, |
|
|
const size_t & |
key_size |
|
) |
| |
|
staticnoexcept |
Generates a random key pair for signing using the specified algorithm and key size.
This method generates both a public and private key, creating a KeyPair
that can be used for signing and signature verification.
- Parameters
-
algo | The signing algorithm to use. |
key_size | The size of the key to generate. |
- Returns
- An Expected containing the generated KeyPair or an error.
◆ Generate() [5/5]
static Expected< KeyPair, Exception > StormByte::Crypto::KeyPair::Generate |
( |
const Algorithm::Sign & |
algo, |
|
|
const std::string & |
curve_name |
|
) |
| |
|
staticnoexcept |
Generates a random key pair for signing using the specified algorithm and curve name.
This method generates both a public and private key, creating a KeyPair
that can be used for signing and signature verification.
- Parameters
-
algo | The signing algorithm to use. |
curve_name | The name of the elliptic curve (e.g., "secp256r1"). |
- Returns
- An Expected containing the generated KeyPair or an error.
◆ operator=() [1/2]
KeyPair & StormByte::Crypto::KeyPair::operator= |
( |
const KeyPair & |
other | ) |
|
|
default |
Copy assignment operator.
Assigns the values from the given KeyPair
instance to the current instance.
- Parameters
-
- Returns
- A reference to the current instance.
◆ operator=() [2/2]
Move assignment operator.
Moves the values from the given KeyPair
instance to the current instance.
- Parameters
-
- Returns
- A reference to the current instance.
◆ PrivateKey()
const std::optional< std::string > & StormByte::Crypto::KeyPair::PrivateKey |
( |
| ) |
const |
|
noexcept |
Returns the private key.
The private key is optional in a KeyPair
. If the private key is not available, the KeyPair
can only be used for encryption and signature verification. Decryption and signing will not be possible.
- Returns
- The private key as an optional string. If the private key is not available, the optional will be empty.
◆ PublicKey()
const std::string & StormByte::Crypto::KeyPair::PublicKey |
( |
| ) |
const |
|
noexcept |
Returns the public key.
The public key is always available in a KeyPair
and can be used for encryption and signature verification.
- Returns
- The public key as a string.
The documentation for this class was generated from the following file:
- /home/runner/work/StormByte-Crypto/StormByte-Crypto/lib/public/StormByte/crypto/keypair.hxx