How to encrypt a large file with OpenSSL using RSA keys

encryptionopenssl

How can I encrypt a large file with a public key so that no one other than who has the private key be able to decrypt it? I don't want to use GPG!

Best Answer

This could be used to encrpyt a file mypic.png, given you already have a private/public keypair in ccbild-key.pem/ccbild-crt.pem. (You can find a guide to creating a keypair in this answer.)

# encrypt
openssl smime -encrypt -aes-256-cbc -binary -in mypic.png -outform DER -out mypic.png.der ccbild-crt.pem

# decrypt
openssl smime -decrypt -binary -in mypic.png.der -inform DER -out mypic.png -inkey ccbild-key.pem

Note that the settings may not reflect best practice in selection of crypto standard (in particular if you read this in the future), also it might not be a good choice performance-wise. (We only use it for sub-1M files in our application.)

Related Question