Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k 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.4k 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/ -outform PEM -pubout

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

openssl rsautl -encrypt -inkey /tmp/ -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

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer
0 votes
1 answer

Browse Categories