2

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?

mis
  • 21
  • 1
  • 2

1 Answers1

4

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
Jacek Konieczny
  • 8,283
  • 2
  • 23
  • 35