gpg 加密和解密
我正在尝试加密和解密字符串。 现在我已经做到了:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试通过同一文件描述符推送要加密的测试 (
echo "hallo" |
) 和密码短语 () (0,这是标准输入)。这些重定向中只有一种可以成功,那就是密码短语。对这两个任务使用不同的文件或文件描述符。
例如,使用文件描述符 #3 作为密码:
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: