entering password into openssl command from shell script
Asked Answered
D

1

5

I am trying to convert a p12 to a pem from a shell script without any user input. I can have the password as a variable within the script.

so when I call:

openssl pkcs12 -in *.p12 -out cert.pem -nodes

The terminal prints "Enter Import Password:" and waits for input.

I tried to pipe the password in with:

echo $PASS | openssl pkcs12 -in *.p12 -out cert.pem -nodes

as well as trying to use a flag with the openssl command but can't figure out how to do this.

Dow answered 19/11, 2014 at 16:40 Comment(3)
What flag did you try?Reinhard
Add -passin pass:12345678 to lineSutherlan
Thanks. I thought passin would only take a file as input...But I got it work with -password stdin, so openssl expects the password to come from stdin, then the pipe work.Dow
I
7

This one liner worked for me-

openssl pkcs12 -in certificate.p12 -password pass:<your_password> -nodes | openssl x509 -noout -enddate
Imperious answered 21/10, 2017 at 0:32 Comment(1)
You saved me, I was putting the password at the end of the line near the -enddate, but it should be before the pipe when opening the certificate. Note that new command is -passin instead of password as indicated above.Expellee

© 2022 - 2024 — McMap. All rights reserved.