我可以使用 ssh 公钥来解密文件吗?

发布于 2024-09-01 02:36:12 字数 188 浏览 7 评论 0原文

我正在尝试找到一种方法来解密“原始”EC2 实例上的加密文件。我使用的这些 EC 实例 (Ubuntu Lucid) 仅保存我的 AWS 创建的公共 ssh 密钥。如果可以使用它来解密文件,我可以向它提供加密文件(例如保存我的 subversion 存储库密码的 bash 脚本)。

那么,我的问题是,我可以使用 ssh 密钥来加密/解密文件吗?

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).

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

债姬 2024-09-08 02:36:12

文件:

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

导出公钥(以防您没有/丢失):

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

用公钥加密文件(任何人都可以拥有此密钥):

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

用私钥解密文件(只有您应该拥有私钥)

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

:解码后的消息:

cat /tmp/decrypted.txt

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
日记撕了你也走了 2024-09-08 02:36:12

您可以使用公钥来加密文件,但需要相应的私钥来解密它。所以,是的,只要您有权访问公钥和私钥,您就应该能够使用 ssh 密钥来加密/解密文件。

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.

瑾夏年华 2024-09-08 02:36:12

如果您只想使用 ssh 密钥进行加密/解密,ssh-vault 可能会很有用,更多信息请参见此处: http://ssh-vault.com/about/

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文