简体   繁体   中英

how to convert ssl private-key.txt to private.key extension

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM