5#include <openssl/rsa.h>
6#include <openssl/ssl.h>
7#include <openssl/err.h>
8#include <openssl/evp.h>
9#include <openssl/opensslv.h>
14 std::ifstream keyfile(filename);
15 std::stringstream buffer;
16 buffer << keyfile.rdbuf();
17 std::string key = buffer.str();
19 BIO* bio = BIO_new(BIO_s_mem());
20 BIO_write(bio, key.c_str(),
static_cast<int>(key.length()));
22 private_key = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
25 context = EVP_MD_CTX_create();
26 EVP_MD_CTX_set_flags(context, EVP_MD_CTX_FLAG_ONESHOT & EVP_MD_CTX_FLAG_FINALISE & EVP_MD_CTX_FLAG_REUSE);
30 std::vector<unsigned char> dummy(256,
' ');
38 EVP_PKEY_free(private_key);
43 EVP_DigestSignInit(context, NULL, EVP_sha256(), NULL, private_key);
44 EVP_DigestSignUpdate(context, message.data(), message.size());
47 EVP_DigestSignFinal(context, NULL, &length);
48 unsigned char* buffer =
new unsigned char[length];
49 EVP_DigestSignFinal(context, buffer, &length);
51 std::vector<unsigned char> result;
52 result.reserve(length);
53 for (
unsigned int i = 0; i < length; i++)
55 result.push_back(buffer[i]);
63 return OPENSSL_VERSION_TEXT;
std::vector< unsigned char > sign(std::vector< unsigned char > digest)
Sign bytes.
std::string openssl_version(void) const
OpenSSL Version.
Signer(std::string filename)
Constructor.