brgs
brgs

Reputation: 806

How to verify passphrase of pem certificate

As the title says. I can verify passphrase easily with php's openssl_pkcs12_read for p12 certs, but it seems like there isn't similar function for pems. Maybe it's impossible to do this with pems?

Upvotes: 15

Views: 55604

Answers (3)

Chris Gallup
Chris Gallup

Reputation: 41

One can also test the pass phrase without passing their password by using:

openssl rsa -noout -in YOUR_PRIVATE_KEY_FILE.pem

If passphrase is entered correctly, then no return.

If passphrase is entered incorrectly, then will return error:

PKCS12 routines:PKCS12_pbe_crypt_ex:pkcs12 cipherfinal error:../crypto/pkcs12/p12_decr.c:86:maybe wrong password

Upvotes: 4

mivk
mivk

Reputation: 14824

Try this if you don't mind the password being on the command-line and in the shell history:

openssl rsa -noout -in YOUR_PRIVATE_KEY_FILE.pem -passin "pass:YOUR_PASSWORD"

or with the password in a file:

openssl rsa -noout -in YOUR_PRIVATE_KEY_FILE.pem -passin "file:/PATH/PASSWORD_FILE.TXT" 

Or build around something like this:

if openssl rsa -noout -in "$KEYFILE" -passin "pass:$PASSWORD" 2>/dev/null; then
    echo OK
else
    echo "Wrong password"
fi

Upvotes: 20

ice13berg
ice13berg

Reputation: 713

Have you tried php's openssl_x509_read? Here.

Or, if you're just using openssl ,openssl x509 -text.

Upvotes: 5

Related Questions