Working with openssl to extract information from a pkcs12 certificate Working with openssl to extract information from a pkcs12 certificate bash bash

Working with openssl to extract information from a pkcs12 certificate


Try this:

$ openssl pkcs12 -in ~/cert.p12 -nodes \    -passin pass:"my password" | openssl x509 -noout -subject

Or this for the common name (ruby to strip trailing whitespace):

$ openssl pkcs12 -in ~/cert.p12 -nodes \    -passin pass:"my password" | openssl x509 -noout -subject \    | awk -F'[=/]' '{print $6}'`.strip`


Copying answer here in order to remove this question from the "Unanswered" filter:

openssl pkcs12 -nokeys -in /Users/[User]/Desktop/ID.pfx -passin pass:${password}


You could also use -passin and -passout which would not prompt you again for manual input. Here is a sample code:

openssl pkcs12 -in seldpush_dev.p12 -passin pass:$password -passout pass:$password | \sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | \openssl x509 -subject -noout

Basically, use -keyword to fetch that value. In your case, -subject.