chris.au
chris.au

Reputation: 1108

GNUPG - stdin encrypted file and passphrase on windows

How can I pipe the passphrase and encrypted file in gpg.exe?

I have tried a few different combinations but I can't get it to work.

Here is my attempt,

C:\>gpg.exe --output [OUTPUT_FILE] --batch --passphrase-fd 0 --decrypt < [INPUT_FILE] < [PASSPHRASE_FILE]

from this I get error

gpg: decrypt_message failed: eof

Swapping the input and passphrase around I get the error

gpg: no valid OpenPGP data found.
gpg: decrypt_message failed: eof

If I don't try and send the encrypted file via stdin then the decryption works fine.

Ultimately what I want to do is decrypt a file based on a file mask with the date timestamp in the file name. Outlined below,

C:\>gpg.exe --output yyyyMMdd.csv --batch --passphrase-fd 0 --decrypt < *_yyyyMMdd_*.txt < [PASSPHRASE_FILE]

I'm not sure if this will work because I can't get the basic scenario working, I would also appreciate if someone could advise me of the best way to achieve this.

Upvotes: 2

Views: 3925

Answers (1)

BellevueBob
BellevueBob

Reputation: 9618

Don't use redirection for the file you want to decrypt, only for the file containing your passphrase:

C:\>gpg.exe --output [OUTPUT_FILE] --batch --passphrase-fd 0 --decrypt [INPUT_FILE] < [PASSPHRASE_FILE]

But honestly, it might be easier for you to remove the passphrase from your key. After all, storing your passphrase in a file is not very secure. Just change your passphrase to a blank and protect your gpg home directory to deny access to any process other than your own.

Upvotes: 3

Related Questions