gpg 加密和解密

发布于 2024-11-10 07:28:47 字数 1175 浏览 3 评论 0原文

我正在尝试加密和解密字符串。 现在我已经做到了:

mis@fasan:~$ echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 > /tmp/1
Enter passphrase:
Repeat passphrase:
mis@fasan:~$
mis@fasan:~$ cat /tmp/1 | gpg --decrypt
gpg: AES256 encrypted data
Enter passphrase: 
gpg: encrypted with 1 passphrase
hallo
mis@fasan:~$ 

它就像我想要的那样工作。现在我已经用文件中的密码进行了尝试,但它不起作用:

mis@fasan:~$ echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 --passphrase-fd 0 < /home/mis/testgpg > /tmp/1
Reading passphrase from file descriptor 0    
mis@fasan:~$
mis@fasan:~$ cat /tmp/1 | gpg --decrypt
gpg: AES256 encrypted data
gpg: encrypted with 1 passphrase

非常有趣的是,他要求提供密码。如果我写错了,我会收到一条错误消息,但如果我写了正确的密码,我不会得到我的密码字符串。 我的目标是达到这个:

mis@fasan:~$ echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 --passphrase-fd 0 < /home/mis/testgpg > /tmp/1
Reading passphrase from file descriptor 0    
mis@fasan:~$
mis@fasan:~$ cat /tmp/1 | gpg --decrypt --passphrase-fd 0 < /home/mis/testgpg
Reading passphrase from file descriptor 0    
gpg: decrypt_message failed: eof
mis@fasan:~$

但这也行不通。有谁知道我做错了什么?

I am trying to crypt and decrypt Strings.
Now I have done this:

mis@fasan:~$ echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 > /tmp/1
Enter passphrase:
Repeat passphrase:
mis@fasan:~$
mis@fasan:~$ cat /tmp/1 | gpg --decrypt
gpg: AES256 encrypted data
Enter passphrase: 
gpg: encrypted with 1 passphrase
hallo
mis@fasan:~$ 

It works just like I want it to work. Now I have tried it with a passphrase out of a file, but it didn't work:

mis@fasan:~$ echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 --passphrase-fd 0 < /home/mis/testgpg > /tmp/1
Reading passphrase from file descriptor 0    
mis@fasan:~$
mis@fasan:~$ cat /tmp/1 | gpg --decrypt
gpg: AES256 encrypted data
gpg: encrypted with 1 passphrase

It is very interesting, that he asks for the passphrase. If I write a wrong one, I get an error message, but if I write the right passphrase, I do not get my cryptet String.
My target is to reach this:

mis@fasan:~$ echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 --passphrase-fd 0 < /home/mis/testgpg > /tmp/1
Reading passphrase from file descriptor 0    
mis@fasan:~$
mis@fasan:~$ cat /tmp/1 | gpg --decrypt --passphrase-fd 0 < /home/mis/testgpg
Reading passphrase from file descriptor 0    
gpg: decrypt_message failed: eof
mis@fasan:~$

But this doesn't work either. Does anyone know, what I am doing wrong?

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

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

发布评论

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

评论(1

孤独患者 2024-11-17 07:28:47

您尝试通过同一文件描述符推送要加密的测试 (echo "hallo" |) 和密码短语 () (0,这是标准输入)。这些重定向中只有一种可以成功,那就是密码短语。对这两个任务使用不同的文件或文件描述符。

例如,使用文件描述符 #3 作为密码:

echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 --passphrase-fd 3 3< /home/mis/testgpg > /tmp/1

You are trying to push both the test to encrypt (echo "hallo" |) and the pass phrase (< /home/mis/testgpg) through the same file descriptor (0, which is stdin). Only one of those redirection can succeed and it is the pass phrase. Use a different file or file descriptor for the two tasks.

E.g., using file descriptor #3 for the pass phrase:

echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 --passphrase-fd 3 3< /home/mis/testgpg > /tmp/1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文