0 votes
1 view
in AWS by (19.2k points)

I'm trying to find a way to decrypt an encrypted file on an 'virgin' EC2-instance. These EC-instances I use (Ubuntu Lucid) only hold my AWS-created public ssh-key. If can use this to decrypt a file, I can feed it encrypted files (for example a bash-script holding a password to my subversion-repository).

So, my question, can I use my ssh-key to encrypt/decrypt a file?

1 Answer

0 votes
by (44.6k points)

The file looks like this:

echo 'This is a secret' >/tmp/msg.txt

Export the public key:

openssl rsa -in ~/privatekey.pem -out /tmp/public.pub -outform PEM -pubout

Encrypt the file with a public key (anyone can read the public key):

openssl rsautl -encrypt -inkey /tmp/public.pub -pubin -in /tmp/msg.txt -out /tmp/file.enc

Decrypt the file with a private key (only you should be able to read the private key):

openssl rsautl -decrypt -inkey ~/privatekey.pem -in /tmp/file.enc -out /tmp/decrypted.txt

The decoded message:

cat /tmp/decrypted.txt

Welcome to Intellipaat Community. Get your technical queries answered by top developers !