SSL_CTX_use_PrivateKey_file() failed
The error error:0906D06C:PEM routines:PEM_read_bio:no start line
is because in both the cert.pem as well as key.pem, don't start off with -----BEGIN CERTIFICATE-----
and -----BEGIN ENCRYPTED PRIVATE KEY-----
.
If you open up your cert.pem and key.pem in a text editor and yank off whatever is there before the BEGIN
markers, you should be good.
When you create a certificate and a key pair using Certificate Signing Request, you won't get this additional information.
I've solved this problem myself. I generated the key.pem using OpenSSL for Windows, when the CMD prompts me to type in the pass phrase, I just typed a Enter since I needn't a pass phrase, but the key.pem was invalid(neither BEGIN
nor END
markers). When I generate the private key in Linux, the terminal prompts I must type a pass phrase and I do. Then I remove the key pass phrase using this command:
openssl rsa -in key.pem -out newkey.pem
After that, I open the key.pem in a text editor, it starts off with -----BEGIN RSA PRIVATE KEY-----
and end up with -----END RSA PRIVATE KEY-----
. And SSL_CTX_use_PrivateKey_file() just works fine!
In my case the error was because the PEM file did not contain both a key and a certificate.
Make sure your file contains both sections:
-----BEGIN PRIVATE KEY----- jhajk838383jks.....
-----END PRIVATE KEY-----
-----BEGIN CERTIFICATE----- yoe55wjcxnshre.....
-----END CERTIFICATE KEY-----
I catenated .key
and .crt
files I already had in my Apache configuration to make a .pem
file.
The 'no start line' error is certainly misleading as you can have a perfectly good "BEGIN" line in your PEM file and still get the error.