我正在尝试加密和解密字符串。 现在我已经做到了:
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:~$
但这也行不通。有谁知道我做错了什么?
最佳答案
您正在尝试通过相同的文件描述符(0,即标准输入)推送加密测试 ( echo "hallo" |
) 和密码短语 ( < /home/mis/testgpg
)。这些重定向中只有一种可以成功,那就是密码短语。对这两个任务使用不同的文件或文件描述符。
例如,使用文件描述符 #3 作为密码:
echo "hallo" | gpg --symmetric --pgp8 --cipher-algo AES256 --passphrase-fd 3 3< /home/mis/testgpg > /tmp/1
关于linux - gpg加密和解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6138555/