StormByte-Crypto 3.1.0
C++26 cryptography module of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Crypto::KeyPair Namespace Reference

Keypairs of the Crypto module. More...

Classes

class  DSA
 DSA keypair. More...
class  ECC
 ECC keypair. More...
class  ECDH
 ECDH keypair. More...
class  ECDSA
 ECDSA keypair. More...
class  ED25519
 Ed25519 keypair. More...
class  Exception
 Exception from the key-pair component. More...
class  Generic
 Abstract keypair. More...
class  RSA
 RSA keypair. More...
class  X25519
 X25519 keypair. More...

Typedefs

using PathView = std::basic_string_view<std::filesystem::path::value_type>
 Borrowed native path characters for allocation-free DLL arguments.

Enumerations

enum class  Type {
  DSA , ECC , ECDH , ECDSA ,
  ED25519 , RSA , X25519
}
 Available keypair algorithms. More...
enum class  StorageFormat { PEM , DER }
 On-disk encoding. More...

Functions

Generic::PointerType Create (Type type, unsigned short bits) noexcept
 Generate a keypair.
Generic::PointerType Load (const StormByte::Safe::SecureBinary &data) noexcept
 Load from one in-memory key (public, private, or concatenated PEM).
Generic::PointerType Load (const StormByte::Safe::SecureBinary &data, const Secure::Password &password) noexcept
 Load from one in-memory key; decrypt if needed.
Generic::PointerType Load (const StormByte::Safe::SecureBinary &publicKey, const StormByte::Safe::SecureBinary &privateKey) noexcept
 Load from separate in-memory public and private keys.
Generic::PointerType Load (const StormByte::Safe::SecureBinary &publicKey, const StormByte::Safe::SecureBinary &privateKey, const Secure::Password &password) noexcept
 Load from separate in-memory keys; decrypt the private key if needed.
Generic::PointerType Load (PathView publicKeyPath, PathView privateKeyPath) noexcept
 Load from separate public and private files.
template<typename Compatibility = void>
Generic::PointerType Load (const std::filesystem::path &publicKeyPath, const std::filesystem::path &privateKeyPath) noexcept
 Caller-side filesystem path adapter for loading separate files.
Generic::PointerType Load (PathView publicKeyPath, PathView privateKeyPath, const Secure::Password &password) noexcept
 Load from separate files; decrypt the private key if needed.
template<typename Compatibility = void>
Generic::PointerType Load (const std::filesystem::path &publicKeyPath, const std::filesystem::path &privateKeyPath, const Secure::Password &password) noexcept
 Caller-side filesystem path adapter for loading separate encrypted files.
Generic::PointerType Load (PathView path) noexcept
 Load from one file (public, private, or concatenated PEM).
template<typename Compatibility = void>
Generic::PointerType Load (const std::filesystem::path &path) noexcept
 Caller-side filesystem path adapter for loading one file.
Generic::PointerType Load (PathView path, const Secure::Password &password) noexcept
 Load from one file; decrypt if needed.
template<typename Compatibility = void>
Generic::PointerType Load (const std::filesystem::path &path, const Secure::Password &password) noexcept
 Caller-side filesystem path adapter for loading one encrypted file.

Detailed Description

Keypairs of the Crypto module.

Key pairs of the Crypto module.

Typedef Documentation

◆ PathView

using StormByte::Crypto::KeyPair::PathView = std::basic_string_view<std::filesystem::path::value_type>

Borrowed native path characters for allocation-free DLL arguments.

Note
Uses wide characters on Windows and bytes on Linux/macOS. The characters must remain valid for the call; Crypto copies them into an owned filesystem path before performing OS operations.

Enumeration Type Documentation

◆ StorageFormat

On-disk encoding.

Enumerator
PEM 

OpenSSL PEM.

DER 

Binary DER.

◆ Type

Available keypair algorithms.

Enumerator
DSA 

DSA.

ECC 

Elliptic-curve encryption.

ECDH 

ECDH.

ECDSA 

ECDSA.

ED25519 

Ed25519.

RSA 

RSA.

X25519 

X25519.

Function Documentation

◆ Create()

Generic::PointerType StormByte::Crypto::KeyPair::Create ( Type type,
unsigned short bits )
noexcept

Generate a keypair.

Parameters
typeAlgorithm.
bitsKey size in bits.
Returns
Keypair pointer.

◆ Load() [1/12]

template<typename Compatibility = void>
Generic::PointerType StormByte::Crypto::KeyPair::Load ( const std::filesystem::path & path)
inlinenoexcept

Caller-side filesystem path adapter for loading one file.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
pathKey file.
Returns
Keypair pointer, or nullptr.

◆ Load() [2/12]

template<typename Compatibility = void>
Generic::PointerType StormByte::Crypto::KeyPair::Load ( const std::filesystem::path & path,
const Secure::Password & password )
inlinenoexcept

Caller-side filesystem path adapter for loading one encrypted file.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
pathKey file.
passwordPassword for encrypted private material.
Returns
Keypair pointer, or nullptr.

◆ Load() [3/12]

template<typename Compatibility = void>
Generic::PointerType StormByte::Crypto::KeyPair::Load ( const std::filesystem::path & publicKeyPath,
const std::filesystem::path & privateKeyPath )
inlinenoexcept

Caller-side filesystem path adapter for loading separate files.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
publicKeyPathPublic file, or empty.
privateKeyPathPrivate file, or empty.
Returns
Keypair pointer, or nullptr.

◆ Load() [4/12]

template<typename Compatibility = void>
Generic::PointerType StormByte::Crypto::KeyPair::Load ( const std::filesystem::path & publicKeyPath,
const std::filesystem::path & privateKeyPath,
const Secure::Password & password )
inlinenoexcept

Caller-side filesystem path adapter for loading separate encrypted files.

Template Parameters
CompatibilityDefaulted to prefer the view overload for native strings.
Parameters
publicKeyPathPublic file, or empty.
privateKeyPathPrivate file.
passwordPassword for an encrypted private key.
Returns
Keypair pointer, or nullptr.

◆ Load() [5/12]

Generic::PointerType StormByte::Crypto::KeyPair::Load ( const StormByte::Safe::SecureBinary & data)
noexcept

Load from one in-memory key (public, private, or concatenated PEM).

Format is auto-detected.

Parameters
dataPEM or DER bytes, for example from a file or #embed.
Returns
Keypair pointer, or nullptr. Elliptic-curve keys load as Type::ECC.

◆ Load() [6/12]

Generic::PointerType StormByte::Crypto::KeyPair::Load ( const StormByte::Safe::SecureBinary & data,
const Secure::Password & password )
noexcept

Load from one in-memory key; decrypt if needed.

Parameters
dataPEM or DER bytes.
passwordPassword for encrypted private material.
Returns
Keypair pointer, or nullptr.

◆ Load() [7/12]

Generic::PointerType StormByte::Crypto::KeyPair::Load ( const StormByte::Safe::SecureBinary & publicKey,
const StormByte::Safe::SecureBinary & privateKey )
noexcept

Load from separate in-memory public and private keys.

Format is auto-detected.

Parameters
publicKeyPublic key bytes, or empty.
privateKeyPrivate key bytes, or empty.
Returns
Keypair pointer, or nullptr.

◆ Load() [8/12]

Generic::PointerType StormByte::Crypto::KeyPair::Load ( const StormByte::Safe::SecureBinary & publicKey,
const StormByte::Safe::SecureBinary & privateKey,
const Secure::Password & password )
noexcept

Load from separate in-memory keys; decrypt the private key if needed.

Parameters
publicKeyPublic key bytes, or empty.
privateKeyPrivate key bytes. Raw DER is taken as encrypted PKCS#8.
passwordPassword for an encrypted private key.
Returns
Keypair pointer, or nullptr.

◆ Load() [9/12]

Generic::PointerType StormByte::Crypto::KeyPair::Load ( PathView path)
noexcept

Load from one file (public, private, or concatenated PEM).

Parameters
pathKey file.
Returns
Keypair pointer, or nullptr.

◆ Load() [10/12]

Generic::PointerType StormByte::Crypto::KeyPair::Load ( PathView path,
const Secure::Password & password )
noexcept

Load from one file; decrypt if needed.

Parameters
pathKey file.
passwordPassword for encrypted private material.
Returns
Keypair pointer, or nullptr.

◆ Load() [11/12]

Generic::PointerType StormByte::Crypto::KeyPair::Load ( PathView publicKeyPath,
PathView privateKeyPath )
noexcept

Load from separate public and private files.

Format is auto-detected.

Parameters
publicKeyPathPublic file, or empty.
privateKeyPathPrivate file, or empty. No default: a single path is Load(PathView).
Returns
Keypair pointer, or nullptr.

◆ Load() [12/12]

Generic::PointerType StormByte::Crypto::KeyPair::Load ( PathView publicKeyPath,
PathView privateKeyPath,
const Secure::Password & password )
noexcept

Load from separate files; decrypt the private key if needed.

Parameters
publicKeyPathPublic file, or empty.
privateKeyPathPrivate file.
passwordPassword for an encrypted private key.
Returns
Keypair pointer, or nullptr.