Openssl
Published in
1 min readSep 25, 2015
Extract keys from .p12
#extract public key certificate
openssl pkcs12 -in certs.p12 -clcerts -nokeys -out mycert.pem
openssl x509 -pubkey -in mycert.pem -noout > mypubkey.pem#extract private key
openssl pkcs12 -in certs.p12 -nocerts -nodes | openssl rsa > id_rsa
Extract all keys from .p12
# extract all keys
openssl pkcs12 -in certs.p12 -nocerts -out private_keys.pem# extract public key certificates
openssl pkcs12 -in certs.p12 -clcerts -nokeys -out certificates.pem
Encryption and Decryption
How it works
First encrypt the file with receivers public key. The encode the encrypted file with base64 and send to corresposing receiver
Receiver decode the base64 stream and get the encrypted file. Encrypted file will be decrypted with private key
Encrypt file
# encrypt with public key
openssl rsautl -encrypt -pubin -inkey mypubkey.pem -in note.txt -out encrypted.txt# base64 encode the encrypted file
openssl base64 -in encrypted.txt -out encoded_encrypted.txt
Decrypt file
# base64 decode the encoded file
openssl base64 -d -in encoded_encrypted.txt -out decoded_encrypted.txt# decrypt the decoded file
openssl rsautl -decrypt -inkey id_rsa -in decoded_encrypted.txt -out decrypted.txt