I have a .pem file (base64-encoded cryptography information). What OpenSSL command-line should I use to detect whether it contains a public key or a private key?
As explained in this StackOverflow question, a .pem can contain both.
Since the contents of the file are juste garbled base64, when sending a .pem certificate to some other machine, I would like to make sure I'm exporting the public key and not giving out my private key.
In the Certificate windows that appears, you should see a note with a key symbol underneath the Valid from field that says, "You have a private key that corresponds to this certificate." If you do not see this, then your private key is not attached to this certificate, indicating a certificate installation issue.
As a practical approximation that should catch most (all?) human mistakes I would recommend just file and grep:
(file $KEYFILE | grep -i private >/dev/null) && echo Private || echo Public-or-unknown
To screen some key material before it goes out:
for f in *; do (file $f | grep -i private >/dev/null) && file $f; done
Empty output = hopefully no secrets, can proceed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With