Unable to load Private Key. (PEM routines:PEM_read_bio:no start line:pem_lib.c:648:Expecting: ANY PRIVATE KEY)

后端 未结 13 1753
暖寄归人
暖寄归人 2020-12-07 14:51

I have a .key file which is PEM formatted private key file. I didn\'t make this file but I got this from somewhere.

I wanted to see its MD5 hash with openssl tool li

相关标签:
13条回答
  • 2020-12-07 15:09
    > I have a .key file which is PEM formatted private key file.
    > ...
    > Here's some asn1parse of the .key file...
    

    That it appears OK with asn1parse leads me to believe its not PEM encoded.


    Is there anything more I can try?

    Because it appears to be ASN.1, try:

    $ openssl rsa -in server.key -inform DER -modulus -noout
    

    Notice the -inform DER to switch between encodings.

    0 讨论(0)
  • 2020-12-07 15:10

    In our case what caused the issue is that the private key we were trying to use was encrypted with a passphrase.

    We had to decrypt the private key using ssh-keygen -p before we could use the private key with the openssl command line tool.

    0 讨论(0)
  • 2020-12-07 15:12

    None of the other answers seemed correct in my case, however I found the real answer here

    My id_rsa file was already in PEM format, I just needed to add the .pem extension to the filename.

    Thanks to

    The possible options to the openssl rsa -inform parameter are one of: PEM DER

    A PEM encoded file is a plain-text encoding that looks something like:

    -----BEGIN RSA PRIVATE KEY-----
    MIGrAgEAAiEA0tlSKz5Iauj6ud3helAf5GguXeLUeFFTgHrpC3b2O20CAwEAAQIh
    ALeEtAIzebCkC+bO+rwNFVORb0bA9xN2n5dyTw/Ba285AhEA9FFDtx4VAxMVB2GU
    QfJ/2wIRANzuXKda/nRXIyRw1ArE2FcCECYhGKRXeYgFTl7ch7rTEckCEQDTMShw
    8pL7M7DsTM7l3HXRAhAhIMYKQawc+Y7MNE4kQWYe
    -----END RSA PRIVATE KEY-----
    

    While DER is a binary encoding format.

    0 讨论(0)
  • 2020-12-07 15:13

    May be the private key itself is not present in the file.I was also faced the same issue but the problem is that there is no private key present in the file.

    0 讨论(0)
  • 2020-12-07 15:15

    Remove any whitespace at the start of the .key file.

    0 讨论(0)
  • 2020-12-07 15:17

    Create CA certificate

    openssl genrsa -out privateKey.pem 4096
    openssl req -new -x509 -nodes -days 3600 -key privateKey.pem -out caKey.pem
    
    0 讨论(0)
提交回复
热议问题