且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我可以使用ssh-public-key解密文件吗?

更新时间:2021-11-21 22:51:19

文件:

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