【问题标题】:gpg crypt and decryptgpg加密和解密
【发布时间】:2011-09-02 13:43:58
【问题描述】:

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

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:~$

但这也不起作用。有谁知道,我做错了什么?

【问题讨论】:

    标签: linux console console-application gnupg


    【解决方案1】:

    您正在尝试通过相同的文件描述符(0,即标准输入)同时推送要加密的测试 (echo "hallo" |) 和密码短语 (&lt; /home/mis/testgpg)。只有一个重定向可以成功,它是密码短语。对这两个任务使用不同的文件或文件描述符。

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

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

    【讨论】:

      猜你喜欢
      • 2018-02-23
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-29
      • 2021-07-12
      相关资源
      最近更新 更多