0

Is it possible to compare encrypted private keys if you do not have the passphrase?
E.g.:
openssl genrsa -out unencryptedprivkey.pem 2048
openssl rsa -in unencryptedprivkey.pem -aes128 -out aes128encprivkey.pem
openssl rsa -in unencryptedprivkey.pem -aes128 -out aes128encprivkey2.pem

cat aes128encprivkey2.pem

!-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,0468AF97F2CA19C8C5860D1BA506B341
MwYCfvtLgYzjCnJNe0MNUKnkjnkzTRG6nQX1BbE9AQEdfEQO1FOJI7qjFNVihITB En0i2lcS7dZ7hswqHt0cPUzKU5tEyMfbDNeCl6mg9QlFeobWFczqAf3Ifq1vKwWr S4src/8POhJsvbK10bqHmlbaBK7wPcKSBvEGP8vt8FtqyE40q1uu9cxAcG4LkpF5 JZHy9svhQoPuz1bqPSTbUaLMxm2YEmdzuDyrC3IyN6dmEYzav93f07JvD7aSYgjV MJuBcVKMt8HbgAKlq9jgB2Ubwsi9RtWTd/e5SRw0x7C1ImdlXwubv724N9NBRV67 4iHgIdpDBit3+5wD400CNOBr4AItts4wpC6ydvLvGtoRrCPHRHk7JwYChT3al1yb 57MFK8chLAgPx2PdHeb6KUB4s7x6E1IJos7DIR2YljEvcCCt75tYufCiOpA1MNN5 b718bOTrmlz4Sh7DCxE4HKSyZdJdpMvEcubHVY9to1HIRUmMBpYV+Yc1q+UZMPJ5 2evRcoW9fVT2eZ33dlg5Cepo80dEbvvBuraAuAU/3AP6GLolh5C5H7VStm7YDPRZ bUAGDTfAfdDPz03xPJt7stv82YG/xFmCTn9cDX2BSUWFCvAaRMp3CIPH/FZXnWO6 uLrdJYjqRmQWTc05sBQ0OtO02I7u/N08qJVT3Qd1a/Cq1NvtnuBnCyL02xlvFpe9 HXf6twDOckCOfGGukVuTaVqAMqiuu2ueypnqX2n/oTI0YCXT+TkuGcSOgRyWt9/k IXio1pIBLw9vIixXd9R3GiMhG//krqROgO92gtW4biePzdaJhGQvQKtaNkaKQw+G x4skI4jsXK5FIllwHQ20D37XUbDcnclI/ukQ1jv9SfMgJ2sYsgvVKVoYJj9Og/cP yv80vAri1/8dIv8usMqWPS1H+V1CPzfI78HmmsHH8JgjZkUjkSrkVYtuW4Sr/ukt hemp0STKPcbdwaseszECw8J3np54fDBRnzCyeMUcHwCUYjhmg2CJcgTjyEEB14QO Egz6uE2d1+eegRf50y7W5upr9mdXxeTrkxk+migYYznN0IWaNZvJhB6qbEulBaBw vlE8/+gBI0CP1YRooUA0tFuOBfT5M3/2PGCOaaXWF+YdU7zAMnf+KRiU+jSUz1zl w3fnWKFTesEF2Sq3llCiY8PerFaR799PqBCUvTgiEZPXQiBBaUs44bkdqRK8U31y s/xFnb9kJs25tBPFU/IK28HuX4xCDK5HLPgBJCjeMsSNSqqxFE1OHC4rQnxjrbjB 0iSxGFbhLVPNTtHUDehNb7iR3NcT+t0DgDKSFuI7kv1uQaHFX6kQmA0s/AdYl2C/ L1low41t4vdXVSgCmJnKFO4Ng1L0M4ACTtnbhgvFWPUhJNR4ZtidqqwK32LDBND2 GPD3zDEGfHe9VNazDoV/htJVaCPfGXgTHzA1PjEgsLSrsR5fm54frHMv2CHdSQzn akOT8TOT5lg/IHSUH/+r2HLRL78TGzhtiWaxdyOuVdnBAPCkiMvCcrKgWg/b2r1i +q4HTUu30fw/PmeeN/+SRmkvYShaWOwH94WEfT2q1sIpWL5JZtkRm/pSqqPOY9+o
-----END RSA PRIVATE KEY-----

cat aes128encprivkey.pem

!-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,6263DD33306AA1F9CFD84FB304FACED9
N6LFCTguNSfeISBSvciYRuMIg/OER9hy8bjwPkoUaLTBoRbvFtku9KaXwje3Mgw0 e+JFtYfjF27ZtHYbk8HFG9z0C20NiwBiFH63U3+YZBJTSKZOHmA2H+d7pT1UV9w5 xXXuf7mPEUDLwKVINF8BIez63kay+fAu6Qu2Q9V8KcjITWf/Q+bTmy+LDzOPn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6szZNz/xPsLV8WXSSXaqVP3Dnerjpi6YDn1+aqBtcLE8M LxnUQuECgYEA/1saPId7iF4aKU+/jJgw9MzPEUgD1T7tV7EAEsIu73MPyCd8/Y3t Wx4CHAZr5ySL+yS4FgxAE1NRAdGawTelFckuBTjZ8tW2V0KzWvOjSOe0EYIzG36i KTjL7LlwxkZVW1kFo/B5vRtYDqde23I5B3vSq9sDgS/T/PTKyZJp7YMCgYEAxNvj vLP7APczkjD4lfUukzie5N2489p0xLKpXXXqOEmN3fdsRAC7stX8Ebwy/zf/PRDe PABMRUyVxhkEJ3jEJ2iQoicMMcFAzzJHMweqL6mEXEvKNUH0AQvyPAmQKu7tdw6Q 2KqRjK8zvYIw1H7NJg5kEUn3yR2eTnuGsmx52dECgYAUs40H9S/VmVNjn/x2aGwn nGb5Dq6I3iYdotLPsoBdlyVjY5glchkY9vDS1s5uma7jeFGYL/wN1QZPMG/sVBeF EZ8yey5oGl1C67xgljnZkjct6DE+fGCnGNynX00+Nbt7wVbMuJUV+J6F6ZmuDq+C 5M3qcsHw+jCkZDAAcWc3AwKBgGXfkTQnQ77VLof59brMvgSL6ZZws3TmWUUtW/40 tjfYwKTclNeANaIvoJmg9hcjaF+2qfsNAGtgXaW9bmvq0D/AmhB/+oyJALv4veXH kqfFpuyIgCUdc2NTRlERddzx9kuFaynk4xuV00W/6Psef5WxHtHfoG4geLsOq78L 6ebxAoGAPPfuY4cHq8PBYcf6++29RUM/n+aCeh+SzO8GpGo+PMaf+6Ax9pCuCZlx DDJ4uGmNcIYOr4fih4+33b2+bfmP95HP77WCYht+5Z6anzyMaliFFoyuE6Z3+FQF ubnsimYRxjDkJyYgyOebDDwwswEg2YQNVDMjTjn6F688ayv18VA=
-----END RSA PRIVATE KEY-----

Passphrase: pass

1

No, you can't.

Generally, speaking, you can only compare two cyphertext together if they share the same IV and key (at least with any modern encryption algorithm).

1

If you could compare the two encrypted keys together, then this would be suggestive of a deep and large weakness of the encryption algorithm. This would be bad news; pray that it does not happen.

Note that even if both files use the same passphrase, they would still differ in IV (or salt for passphrase derivation), and they again should evade attempts at comparisons. If you have two files which use distinct IV, then you should not be able to detect whether they use the same key, or same contents, or both.

Only if you know the passphrase(s) can you compare the files, by decrypting both and comparing the clear contents (here, RSA private keys, but what I say applies to any kind of contents).


All of the above is about noticing that the two RSA private keys are identical in general. There are particular cases which allow you to conclude:

  • If your two files are byte-to-byte identical, then, of course, they are identical, and thus contain the same RSA private key encrypted with the same passphrase and IV.

  • If the two files differ in length (length of the Base64-encoded element) then the RSA keys are distinct. You may observe a slight difference in size if both files work over the same key but with distinct encryption algorithms (e.g. one uses AES-CBC while the other uses 3DES-CBC). If the same encryption algorithm is used (including mode of operation and padding), then a difference in size implies a difference in size of the contents. Since RSA private keys are ASN.1 objets with DER encoding, the cleartext encoded size of a RSA private key is fixed for a given key; therefore, distinct content sizes (even by a single byte) imply distinct keys.

  • Or one used excessive padding just to be a pain. Don't know if anything allows padding an entire block or not, but there isn't any reason it couldn't theoretically be done if someone was trying to avoid same length. – AJ Henderson May 21 '14 at 13:25
  • Since the encryption format used by OpenSSL is not specified anywhere, except as "what OpenSSL does", it is a bit difficult to declare that something is "allowed" or "not allowed". In SSL/TLS (where padding also occurs for CBC encryption), minimal length padding is enforced for SSL 3.0, but TLS 1.0 allows extra blocks. – Thomas Pornin May 21 '14 at 13:44

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.