jgoenetxea
10/21/2019 - 12:26 PM

How to get string of error in OpenSSL

In therminal, call the method errstr of OpenSSL. For example, you can get error information with the function:

std::string getOpenSSLError() {
    BIO *bio = BIO_new(BIO_s_mem());
    ERR_print_errors(bio);
    char *buf;
    size_t len = BIO_get_mem_data(bio, &buf);
    std::string ret(buf, len);
    BIO_free(bio);
    return ret;
}

And this gives something like:

140737353706016:error:04066076:lib(4):func(102):reason(118):rsa_eay.c:388:

so, you can get the error:04066076 part and write it like:

$ openssl errstr 0x04066076
error:04066076:rsa routines:RSA_EAY_PRIVATE_ENCRYPT:unknown padding type