10#include <openssl/err.h>
11#include <openssl/pem.h>
12#include <openssl/types.h>
19 ERR_print_errors_fp(stderr);
23 int length = BN_bn2mpi(num,
nullptr);
24 QVector<unsigned char> data(length);
25 BN_bn2mpi(num, data.data());
27 result.insert(0,
reinterpret_cast<char*
>(data.data()), data.length());
32 auto d =
reinterpret_cast<const unsigned char*
>(array.data());
33 BIGNUM* result = BN_mpi2bn(d,
34 array.length(),
nullptr);
45 int dataSize = BIO_ctrl_pending(bio);
46 byteArray.resize(dataSize);
47 if (BIO_read(bio, byteArray.data(), dataSize) != dataSize) {
55 BIO* bio = BIO_new_mem_buf(byteArray.constData(), byteArray.length());
63 BIO* bio = BIO_new(BIO_s_mem());
64 if (PEM_write_bio_PUBKEY(bio, ssl_keys) != 1) {
79 BIO* bio = BIO_new(BIO_s_mem());
80 if (PEM_write_bio_PrivateKey(bio, ssl_keys,
nullptr,
nullptr, 0,
nullptr,
nullptr) != 1) {
static BIO * byteArrayToBio(const QByteArray &byteArray)
byteArrayToBio This method creates the BIO struct from the Qt QByteArray object.
static QByteArray bignumToArray(const BIGNUM *num)
bignumToArray This method converts openssl BIGNUM into byteArray
static void printlastOpenSSlError()
printlastOpenSSlError This method prints the latest ssl error message.
static QByteArray extractPublcKey(EVP_PKEY *ssl_keys)
extractPublcKey This method extracts the public key from the ssl (pem) structure.
static BIGNUM * bignumFromArray(const QByteArray &array)
bignumFromArray This method converts the Qt bytes array into the opensll big num.
static QByteArray bioToByteArray(BIO *bio)
bioToByteArray This method converts the openssl BIO to the QByteArry
static QByteArray extractPrivateKey(EVP_PKEY *ssl_keys)
extractPrivateKey This method extracts the private key from the ssl (pem) structure.