the callback function is not called by PEM_read_PrivateKey

Skip to first unread message

May 12, 2017, 12:12:11 AM5/12/17
Hi there,

I encountered a problem with PEM_read_PrivateKey that did not call the password callback function I passed into.
the pseudo code is like this:

static int pass_cb(char* buf, int size, int rwflag, void* u){
int len = strlen((const char*)u);
memcpy(buf, u, len);
return len;

EVP_PKEY pkey = PEM_read_PrivateKey(fp, NULL, pass_cb, "password");

the code above works if no password set in the private key pem file. But when I set the password it fails to read and return NULL. What I confuse is the callback function is never called.

How can I solve it? Thanks in advance.

The way of generating the private key pem file is:
openssl genrsa -des3 -out XXXX 2048

Jack Huang

May 16, 2017, 12:07:11 AM5/16/17
No one replies but I resolve this problem.

The reason that callback function does not work is that I did not call to load the algorithm. After I added to call OpenSSL_add_all_algorithm function, the callback function was called.

I found that the answer always in the source code of openssl.

Robert Rodriguez

Jul 19, 2023, 7:25:15 AMJul 19
As time goes by, it’s normal for parts of your garage door to get worn and in need of replacement.

Breaking Bad

Jul 19, 2023, 12:35:55 PMJul 19
about this topic you can read more on this link very helpfull

Reply all
Reply to author
0 new messages