我可以使用ssh-public-key解密文件吗? [英] Can I use my ssh-public-key to decrypt a file?
问题描述
我正在尝试找到一种在原始 EC2实例上解密加密文件的方法。我使用的这些EC实例(Ubuntu Lucid)仅持有由AWS创建的公共ssh密钥。如果可以使用它解密文件,则可以将其加密文件(例如,一个bash脚本将密码保存到我的Subversion存储库中)。
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 subversion-repository).
问题,我可以使用ssh密钥加密/解密文件吗?
So, my question, can I use my ssh-key to encrypt/decrypt a 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
Th解码后的邮件:
cat /tmp/decrypted.txt
这篇关于我可以使用ssh-public-key解密文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!