I need to generate the most secure private key.
Usually I use a command:
openssl genrsa -des3 -out mykey.key 2048
Is triple DES secure enough?
Is 2048 large enough?
Are there any other ways to make the private key stronger?
I need to generate the most secure private key.
Usually I use a command:
openssl genrsa -des3 -out mykey.key 2048
Is triple DES secure enough?
Is 2048 large enough?
Are there any other ways to make the private key stronger?
Using AES and 4096 bit RSA would certainly help. At least openssl uses 3 key triple DES but that means both the triple DES and the RSA private key are stuck at a security strength of 112 bits. See https://keylength.com for information on key strengths. 112 bit is just enough but a bit too close for comfort; I'd sleep better with 128 bit security.
openssl genrsa -aes128 -out mykey.key 4096
Note that 3DES is used in CBC mode, offering confidentiality only. That means that an adversary could change the value of your private key without you knowing it. If that's OK depends on your situation - an attacker may not be able to reach your private key or maybe you're just interested in keeping the private key / messages confidential.
You might consider storing the keys in a PKCS#12 container instead, which offers just a bit more security. You'd need a certificate with the public key to do so though. Unfortunately the genrsa
command doesn't seem to allow any authenticated mode of encryption such as AES-GCM. Possibly you could place a signature over the generated private key (in case you have a different private key used for code signing around). Or you could store a hash over the private key file somewhere safe and compare before using it.
The weakest point of password encryption is always the password. Older command line openssl
, before 1.0.0, uses a pretty weak password based key derivation function (with a single iteration count). Newer openssl
fortunately uses PBKDF2 with a - still low but better - iteration count of 2048 (see the comment of Dave below). You may increase this count using -iter N
command line option. More importantly, you can avoid issues by generating a very strong password, storing the strong password in a password manager of some sorts. Chances are that you won't be able to remember a really strong password (or the password may simply be not as strong as you assume).
Above advice can be used to generate a more secure private key; there is no such thing as a most secure private key. If there would be such a thing, then I would doubt that you could use (software only) OpenSSL command line to generate it.
Secure enough for what? This really depends on your use case. From my own reading RSA 2048 is still generally considered secure for now based on time to break key using publically available methods, and is very widely used. For some use cases, as others have said, you may wish to consider longer key lengths. Be aware that some applications may only support RSA keys up to a certain size though.
As for 3DES I've not regarded it as secure for some years now. The AES family is well established and widely supported, and can provide equivalent security with much shorter key lengths than RSA. Other algorithms are also available too.