开发者

Can I use my ssh-public-key to decrypt a file?

I'm trying to find a way to decrypt an encrypted file on a '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 subver开发者_C百科sion-repository).

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


The file:

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

Export public key (in case you don't have it/lose it):

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

Encrypt file with public key (anyone can have this key):

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

Decrypt the file with private key (only you should have the private key):

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

The decoded message:

cat /tmp/decrypted.txt


You can use a public key to encrypt a file but you will need the corresponding private key to decrypt it. So, yes, you should be able to use your ssh-key to encrypt/decrypt a file, as long as you have access to both the public and private key.


If you just want to encrypt/decrypt using your ssh keys, ssh-vault could be useful, more info here: http://ssh-vault.com/about/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜