5

I generate key/cert using openssl

openssl.exe req -x509 -days 1000 -newkey rsa:1024 -keyout key.pem -out cert.pem

It prompts for a password. I guess that the password is used for key encryption. However I haven't specified any cipher. What cipher is used in this case?

Vladimir Zhilyaev
  • 175
  • 1
  • 2
  • 11

1 Answers1

4

The default cipher is DES-EDE3-CBC, which is three-key triple DES EDE in CBC mode. You can see this in the source code file req.c.

cipher=EVP_des_ede3_cbc();

If you are using an OpenSSL version compiled with the option OPENSSL_NO_DES, then the library will not encrypt the key by default. This is the same behavior as if you pass the -nodes argument.

An easier way to figure this out is just to look at your key file. It announces the cipher in the PEM header.

$ cat key.pem
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,CAFD88DF2EF2EE81
...
Community
  • 1
  • 1
indiv
  • 17,306
  • 6
  • 61
  • 82
  • 2
    There are no headers just `-----BEGIN ENCRYPTED PRIVATE KEY-----`. But the source code explains a lot. – Vladimir Zhilyaev Sep 15 '11 at 08:26
  • @Vladimir: Good to know. I guess the PEM header must depend on the OpenSSL version. – indiv Sep 15 '11 at 15:05
  • 1
    @fernandohur: Updated to github repo. – indiv Apr 09 '14 at 00:18
  • 2
    Per Sep15'11: yes. OpenSSL has long supported 'legacy' algorithm-specific formats (BEGIN RSA PRIVATE KEY, BEGIN DSA PRIVATE KEY, BEGIN EC PRIVATE KEY) which are optionally PB-encrypted using the PEM header, and the generic standard PKCS#8 formst which has two options: clear (BEGIN PRIVATE KEY) and encrypted within the ASN.1 (BEGIN ENCRYPTED PRIVATE KEY). Displaying the latter with `openssl asn1parse` decodes from ASN.1 the pbe-algorithm and parameters (salt & count). From version 1.0.0 generic commands `req pkcs8 pkcs12 genpkey pkey` use PKCS#8 instead of legacy formats. – dave_thompson_085 Jul 10 '14 at 16:11