Brief Steps
-
Generate Private Key:
openssl genpkey -algorithm RSA -out private_key.pem -aes256 -pass pass:your_password openssl genpkey -algorithm RSA -out private_key.pem -
Generate Public Key:
openssl rsa -pubout -in private_key.pem -out public_key.pem -passin pass:your_password -
Generate Symmetric Key:
openssl rand -base64 32 -out symmetric_key.bin -
Encrypt File with Symmetric Key:
openssl enc -aes-256-cbc -salt -in plaintext_file -out encrypted_file.enc -pass file:symmetric_key.bin -
Encrypt Symmetric Key with Public Key:
openssl rsautl -encrypt -inkey public_key.pem -pubin -in symmetric_key.bin -out symmetric_key.bin.enc
What If You Lose the Public Key and Symmetric Key?
If you lose both the public key and the symmetric key, you cannot regenerate them to decrypt the files. Encryption is based on the unique keys generated initially. Losing these keys means losing access to the encrypted data. Always ensure you securely back up your keys.