OpenSSL provide private key as string

Viewed 37

In OpenSSL 3.0 is it possible to provide the private key for decryption as a string. I want to store the key inside some database and not as a file. Therefore i want to call OpenSSL with the key as a string not with the filepath.

I use windows and then run OpenSSL with the shell. The key is stored as in PEM format.

I now want to execute OpenSSL like in this bash script.

key="-----BEGIN RSA PRIVATE KEY-----
<key data>
-----END RSA PRIVATE KEY-----"

command="openssl rsautl -decrypt -inkey $key -in license.enc -keyform PEM"
eval $command

So far I couldn't get it running and on the RSA OpenSSL page i saw no such option. But maybe someone has some solution for this.

1 Answers

Yes, you can use -keyform PEM. PEM stands for Privacy Enhanced Mail, i.e. it is explicitly designed for textual interfaces.

You would get text file that starts with:

-----BEGIN ENCRYPTED PRIVATE KEY-----
<Base64 encoded encrypted private key>
-----END ENCRYPTED PRIVATE KEY-----

The actual encoding is specified in RFC 5958: Asymmetric Key Packages.


Beware that this is an old standard, you want to use PBES2, a strong password and a high iteration count, specified during key (pair) generation.

Related