0

I got pvt-key.txt, certificate.crt and bundle.crt files from godaddy. I am setting ssl for node js backend using https options

var httpsoptions = {
    key: fs.readFileSync("pvt-key.txt"),
    cert: fs.readFileSync("certificate.crt")
};

but it is not working.

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line

I also converted .txt to .pem but there is same error. if I generate key from this command

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privateKey2.key -out certificate2.crt

then it works. I think there should be .key extension instead of .pem or .txt. Please help me to convert file into .key extension. Thank you in advance.

imskm
  • 780
  • 1
  • 14
  • 27

2 Answers2

4

The extension of the file doesn't matter so much, but the contents of the file do. I suspect node wants a PEM encoded private key. You can convert a DER encoded private key to a PEM one like this:

openssl rsa -in pvt-key.txt -outform pem -out pvt-key.key
vcsjones
  • 138,677
  • 31
  • 291
  • 286
  • 5
    `unable to load Private Key` `140456286238464:error:0906D06C:PEM routines:PEM_read_bio:no start line:../crypto/pem/pem_lib.c:691:Expecting: ANY PRIVATE KEY` I'm getting this error. – imskm Feb 04 '19 at 16:35
  • @SureshMaurya i'm facing the same issue. Did you find a solution? – Neville Katila Aug 05 '20 at 18:51
  • I didn't find any solution. so I have set ssl with apache2 and used nodejs backend with proxy – imskm Jun 07 '21 at 08:43
  • first i did next in my privatkey.txt (get read of BOM): https://stackoverflow.com/a/54026652/3877632 and then i started openssl rsa -in pvt-key.txt -outform pem -out pvt-key.key – Sergii Jul 23 '21 at 13:20
1

In order to accomplish this, @vcsjones provided the solution I was able to use.

openssl rsa -in pvt-key.txt -outform pem -out pvt-key.key

But, I got the same error as others: Expecting: ANY PRIVATE KEY.

My fix was found in https://stackoverflow.com/a/54026652.

Open the key file in Notepad++ and verify the encoding. If it says UTF-8-BOM then change it to UTF-8. Save the file and try again.

Colton
  • 11
  • 2