Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 839
brgs Avatar asked Oct 08 '14 05:10

brgs


Video Answer


2 Answers

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
like image 156
mivk Avatar answered Jan 03 '23 20:01

mivk


Have you tried php's openssl_x509_read? Here.

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

like image 42
ice13berg Avatar answered Jan 03 '23 20:01

ice13berg