OpenSSL error : unable to load Private Key

banderas20

Active Member
Joined
Aug 1, 2018
Messages
101
Reaction score
42
Credits
793
Hi!

I have created a public-private keypair with ssh-keygen and I have both id_rsa and id_rsa.pub.

I'm trying to encrypt/decrypt files with openssl.

If I cypher the file with

Code:
cat plain_file | openssl rsautl -encrypt -pubin -inkey /tmp/id_rsa.pub > /tmp/encrypted.txt

it works.

I try to decypher it with the private key of the remitent user with this command

Code:
cat /tmp/encrypted.txt | openssl rsautl -decrypt -inkey id_rsa

But I get this error:

Code:
unable to load Private Key
139651099592000:error:0909006C:PEM routines:get_name:no start line:../crypto/pem/pem_lib.c:745:Expecting: ANY PRIVATE KEY

After some openssl manipulations, the contents of the private key begin with:

Code:
-----BEGIN RSA PRIVATE KEY-----

and then with
Code:
-----BEGIN OPENSSH PRIVATE KEY-----

By the way, the encryption didn't work at first with the ssh-keygen generated public file. I had to convert it with:

Code:
ssh-keygen -f id_rsa.pub -e -m PKCS8 > id_rsa2.pub

I'm pretty lost and I don't know what's going on.

Can you shed some light on this?

Thanks in advance!

PS: running Ubuntu 20.04
 

Members online


Top