How to test passphrase of openssl rsa certificate keyfile

Revision history
Tags: openssl bruteforce passphrase bash

I needed a way to quickly test a lot of different passphrases to a passphrase-protected certificate.key file. So I started out with the slow approach

$ openssl rsa -check -in certificate.key
Enter pass phrase for certificate.key:

Okay, now I want to test them in fast succession. The below snippet will ask you for the password until openssl exits with 0

$ $(exit 1); while [ $? -ne 0 ]; do openssl rsa -check -in certificate.key; done

At least now I can just keep on typing until I find the right one.

The first $(exit 1) is to make the initial $? check return something else than zero. Maybe bash has a do…while too, but this works.

If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.