0

If I create a private key via:
openssl req -x509 -newkey rsa:2048 -out cert.crt
then OpenSSL writes the private key to the file privkey.pem and if you do not provide the -nodes parameter it will encrypt the private key. Which default encryption is used?

A private key generated with this command: cat privkey.pem :

-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIo1rE/z2PcrMCAggA
MBQGCCqGSIb3DQMHBAiDRNWrVvL7CQSCBMgkkOxb7ovb6T0xPjl40T64qNeMhYav
lqXpBLdZZGAnu6Y+Cl4yhr9/Aqnt6wWWf8Dlbdd/cRxenZ1Y+bAhiXWTVNxqMX9I
Qjk2pIpjSkIVSM3tt47XGX+7qIEQxGBaM9yq8U8FjkvkvlVFvJhhbMZQLB0wxheC
+P/YA2co74u51DZr2YKf8Oo/ZVpQ3ivv2Nv7HCDMsymQKylFtOWWup20jAUMrcVx
VAu+Nn95XYa9yBXGMxMw/52p9/FZMcgtCG5EdITP/xerVh0Qrl+aZWYs9n6yl25K
pQ7eboewA8hDHg0CrOsImm4KquB1bhHQTL8Ns5xvq7c43PEUi6CTu4/5bNlkgg71
/y9zzJH1K3xvqS2rb7tjOYLyDMvJkHguNL0WG/SxetArppdrA3wwuBeSogCEFbKE
dXoQwTPf56uMbVXjHIHCJKnn6oRNDBAUgYvd3ifsiZX0MF1Tll64iqLgUilAItoa
wASWsudJCb0HhXR73hmtPC+BQECtsXfRYmCg/ffKtZZIqXRplECWDQR8F0kcsvj1
rZQDffFKGiv9ftW6bS51a0xa1WGpIgtcNeLtz0JBGkZwN3ykQCGDkk2khBGFYxfu
Xkm2G6cuwVMDg8ekg0ie95Zj2nCjS2TtnpKFiX+kxjPmfgTFzdd9jdVyA3ZEpfC/
HZRwEfoaXDgiUP6nOBEB00VLXkjoTw7oFheP8LkX9yJkGokXeSstyl3YXyFvTbNs
vk1oa4qyTmTAaWWIpkYDFc/8p6wtQpYLqkz8eyKiNDsZIxpo5upyya1U3dEuX1Pu
XCoHDsR6t+OINW2CCtMh2VhG5FRMK0sRPDGfOof32/HbIRE/mJf+cyxdk12aXrbu
3kiKxM72LJiEmcP2Yzw9Wbgnen5zBZlLEcLopHqVdWZS1QNKvpGHl+drUAGmGGIZ
fB4evfS2YLmZrhP01nAqNwRHntJXlyoOWKsJz9F6RAA87tGRhAuKX9R7j6vMFrU8
83RL3JAqnt1AvSOSkd8NMJb041aSKvlRcGC1Gzw/kebzQTy5m4PZDiNrgnRGtucO
KPwyMA43HnObY4apD5H8VQrgREp+o1Rnjnvx3+l8o7SuGXf7CqMT6B2kpYgECSP5
9f3YNLkxGZFAoD5G4QPQRHLJmoFsiZ25bYVjleCHIR05WkktV6ps9Hk5qyQocmaU
Agf4opOJfV3KoL3czcnNLdXzG+O6q1n9W+9OCI7ku+Z/v+K8sQkUaH0qjc8w3tV/
Bjq+6kvyk70V9rftbu0yu2gBXqjTdtCE4jhM4pdAGpC2iQr0pKGMRYaSDqNbXtZX
bRreZTxxk8mI+mEjpIyA8jrm0E6jdBd2M0SLI4VCUdkINyk1zRZp+A2zZMUhMp5V
jC2syFs2Od19Ax7WVj+bkDsRSF0TKdpp8/hC9zEzz+oztrhHOG3+sfJJznjm4ZtW
Wm2Wwa5PVQxNVIXT5kX6/HNBdgRdc09bYAo5KPXgeNNgd7Jpz1GinEIR4y8mZa8s
DXkBlXfew+jzHA7eqRSWdwVHvlj9an6snSuBeKjNYKew9zRTX1ANFpq4Pa9mV+LI
/ckYfEoHD3wLWohzNs42dNvtj4DWeqlIHiu5dEpLMjxKeMvqMFxP/SZufE3VCMN+
sMY=  
-----END ENCRYPTED PRIVATE KEY-----

If you generate an RSA private key with:
openssl genrsa -out privkey2.pem 2048
then it is not encrypted by default. If you add -aes256 (or anything else supported) the output will be:
cat privkey2.pem

-----BEGIN RSA PRIVATE KEY-----  
Proc-Type: 4,ENCRYPTED  
DEK-Info: AES-256-CBC,D02DE734A8C2DBA625FC4180E7AECC78

T6KNkW3KdCoIaAoLqBaDZIqFbG9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F+BJiAZL6Evfj5IQA4V7xpbdt/izjIjQAeOT8UejVs9XJGu90sLlDXlnBLxowV
K1gqU5kj1Uqt3kzU7omokNGM8LRaiPj6brWt3zOzWiyQb0RUGHbm7tEVQXcoAa8h
SEtZRPmUgyIiLIA23uASVUcV7qL4TYlO4mL1KeaC/8ZAEjFAECQSNu6l80lChunE
jbftFHV9vPZkyiM3Sfjv49PNoJ2v7NdBUTZr+ajiDIi1AW7lXmrcIBHo15a4+pHU
PvMvJXO5cXwexzbuBADicXcq1PooZogs6mFlHuDDBb9avnZhVTk+yq+Ii8OTvDVi
ZdFxQhxB6FbV72xdqRXvaqwujcvQRWVmUM4jUR+WQR1ZcW1jl1UjJKu+CcfmbjPG
RlK10HH4CId3VqHsYUhf2JuzLcRwR4dng5Z/Ye3c0hip0QRBWyp/HzVh66ItPtB9
A2UIk2IBvMI9YPciXTWSjcZogemRH1GL0ZiE0Lgma9iPttdWSofL0yJ09lUW3bR6  
-----END RSA PRIVATE KEY-----

I did not find any command to get the type of encryption.

The passphrase for both are: pass.

  • Actually req -newkey if you don't specify on the commandline the new key is encrypted or not based on the setting in the config file for encrypt_rsa_key or encrypt_key or else a default of yes; in the 'standard' upstream config this used to be 'yes' but could and can be changed to 'no'. – dave_thompson_085 Jul 6 '17 at 5:16
1

I think the -nodes switch almost gives it away. It uses 3DES in CBC mode, the one which is specified in this RFC. The author's FAQ page of this specific OpenSSL tool mentions this.

You can confirm this using the source code. It is first set to its default and subsequently reset if the user has supplied the -nodes switch.

  • openssl pkcs12 does default to 3des-cbc, but with PKCS5/7-style padding not the one specified for PPP -- but nothing in the Q uses pkcs12 or anything relating to PKCS12 format. genrsa uses 'legacy' format based on PKCS1 (rfc2313,2437,3447) plus PEM-like encryption (rfc1421) using any supported cipher; req -newkey (in 1.0.0+) uses PKCS8 (rfc5208) with 3des-cbc if enabled (and compiled) as shown in StackzOfStuff's (later) answer. – dave_thompson_085 Jul 6 '17 at 5:14
2

des-ede3-cbc

OpenSSL will tell you that encryption is des-ede3-cbc if you use asn1parse.

Command:

$ openssl asn1parse -in privkey.pem -i -dlimit 16

Output:

    0:d=0  hl=4 l=1294 cons: SEQUENCE
    4:d=1  hl=2 l=  64 cons:  SEQUENCE
    6:d=2  hl=2 l=   9 prim:   OBJECT            :PBES2
   17:d=2  hl=2 l=  51 cons:   SEQUENCE
   19:d=3  hl=2 l=  27 cons:    SEQUENCE
   21:d=4  hl=2 l=   9 prim:     OBJECT            :PBKDF2
   32:d=4  hl=2 l=  14 cons:     SEQUENCE
   34:d=5  hl=2 l=   8 prim:      OCTET STRING
      0000 - a3 5a c4 ff 3d 8f 72 b3-                          .Z..=.r.
   44:d=5  hl=2 l=   2 prim:      INTEGER           :0800
   48:d=3  hl=2 l=  20 cons:    SEQUENCE
   50:d=4  hl=2 l=   8 prim:     OBJECT            :des-ede3-cbc
   60:d=4  hl=2 l=   8 prim:     OCTET STRING
      0000 - 83 44 d5 ab 56 f2 fb 09-                          .D..V...
   70:d=1  hl=4 l=1224 prim:  OCTET STRING
      0000 - 24 90 ec 5b ee 8b db e9-3d 31 3e 39 78 d1 3e b8   $..[....=1>9x.>.

And according to the OpenSSL documentation, des-ede3-cbc means Three key triple DES EDE in CBC mode.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.