Some of my colleague give me 2 file of private key (one is encrypted and the other is decrypted) and a passphrase. But it seems that is the wrong passphrase.

Is it even possible to recover the pass phrase with the ecrypted and decrypted private key files?

  • Is it the same private key, once in an encrypted file and once in a file that is not encrypted?
    – lab9
    Jun 30, 2020 at 10:23
  • Yes, that's what my colleague said to me.
    – bizard
    Jun 30, 2020 at 10:42
  • Theoretically recoverable by bruteforcing, but chances are low in practical terms (unless the passphrase was quite weak). Simplest solution: Use the not encrypted file to create a new encrypted file with a new passphrase.
    – lab9
    Jun 30, 2020 at 10:48

2 Answers 2


This is known as a known-plaintext attack. From the Wikipedia article quoted above:

The known-plaintext attack (KPA) is an attack model for cryptanalysis where the attacker has access to both the plaintext (called a crib), and its encrypted version (ciphertext). These can be used to reveal further secret information such as secret keys and code books.

Modern encryption algorithms such as AES are designed to be highly resistant to known-plaintext attacks, however earlier encryption algorithms were susceptible to known-plaintext attacks. For example, with XOR encryption, it is trivial to find the encryption key given the ciphertext and the plaintext.

  • Plus an AES-level attack even if possible would only give the key, not the passphrase from which the key was derived as the Q asked. And since the key derivation is salted, it wouldn't give the key for any other file using the same passphrase. Jul 1, 2020 at 0:45

As already stated in my comment above, the simplest solution in the given case (as per OP, they have the unencrypted key file):
Use the not encrypted file to create a new encrypted file with a new passphrase:

openssl rsa -in unencrypted.key -out new.key
  • That command does not create an encrypted key file (and assumes PEM which is not always the case even with OpenSSL). If you add -$cipher it creates the 'legacy' format file using very poor and usually breakable key derivation (EVP_BytesToKey(niter=1), see numerous existing Qs). pkcs8 -topk8 [-v2 plaincipher] or in 1.0.0 up for PEM only pkey -$cipher is much better. Jul 1, 2020 at 0:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .