fourdst_plugin 0.0.1a
C++ Plugin Manager
Loading...
Searching...
No Matches
fourdst::crypt Namespace Reference

Namespaces

namespace  utils
 

Classes

struct  EVP_MD_CTX_Deleter
 
struct  EVP_PKEY_Deleter
 Custom deleter for OpenSSL EVP_PKEY objects. More...
 
class  PublicKey
 Represents a public key for cryptographic operations. More...
 

Typedefs

using Unique_EVP_PKEY = std::unique_ptr<EVP_PKEY, EVP_PKEY_Deleter>
 Unique pointer type for managing EVP_PKEY objects with automatic cleanup.
 

Functions

bool verify_signature (const PublicKey &key, const std::vector< unsigned char > &data_to_verify, const std::vector< unsigned char > &signature)
 Verifies a digital signature against given data using the provided public key.
 

Typedef Documentation

◆ Unique_EVP_PKEY

using fourdst::crypt::Unique_EVP_PKEY = std::unique_ptr<EVP_PKEY, EVP_PKEY_Deleter>

Unique pointer type for managing EVP_PKEY objects with automatic cleanup.

Function Documentation

◆ verify_signature()

bool fourdst::crypt::verify_signature ( const PublicKey & key,
const std::vector< unsigned char > & data_to_verify,
const std::vector< unsigned char > & signature )

Verifies a digital signature against given data using the provided public key.

This function verifies that the signature was created by the private key corresponding to the provided public key and that the data has not been tampered with.

Parameters
[in]keyThe public key to use for verification.
[in]data_to_verifyThe data that was signed.
[in]signatureThe signature to verify.
Returns
bool True if the signature is valid, false otherwise.
Exceptions
std::runtime_errorIf:
  • The public key is invalid or null.
  • Memory allocation for the verification context fails.
  • The verification context cannot be initialized.
  • An error occurs during the verification process.
Note
The function uses the default digest and padding scheme appropriate for the key type.
Example
try {
fourdst::crypt::PublicKey pubKey("public_key.pem");
std::vector<unsigned char> data = {'t', 'e', 's', 't'};
std::vector<unsigned char> signature = get_signature(); // Get signature from somewhere
if (fourdst::crypt::verify_signature(pubKey, data, signature)) {
std::cout << "Signature is valid" << std::endl;
} else {
std::cout << "Signature is invalid" << std::endl;
}
} catch (const std::exception& e) {
std::cerr << "Error: " << e.what() << std::endl;
}
Represents a public key for cryptographic operations.
Definition public_key.h:51
bool verify_signature(const PublicKey &key, const std::vector< unsigned char > &data_to_verify, const std::vector< unsigned char > &signature)
Verifies a digital signature against given data using the provided public key.
Definition crypt_verification.cpp:18