Decrypting symmetrically encrypted text in Command Line (CL) results in error message?

Einar Ryeng einarr at
Wed Nov 27 20:56:44 CET 2013

On Wed, Nov 27, 2013 at 12:35:51PM +0100, Sin Trenton wrote:
>  1. copy the snippet
>  2. paste it into a txt file
>  3. save the file
>  4. use "gpg -d file.txt"
> Is it possible to replace steps 2 and 3 by pasting in the text in the CL?

It would surprise me if that wasn't possible.

> I've tried "gpg [Enter]", but I always get the message "decryption
> failed: bad key" as you can see below.
> Everything below the encrypted message happened automatically when I
> pasted in the text first time, though next time it did wait for me
> to supply the passphrase, with same "bad key" result, however.
> Note that the last line "-----END PGP MESSAGE-----" disappears.
> Also, the prompt does not return to the standard ">", until I have
> done a Ctrl+Z or Ctrl+C.

I'm guessing that one of two things is happening here, due to the use of STDIN
both to provide the encrypted message and as the way to enter the password:

1) Some buffer gets full and gpg asks for the password to start processing the
encrypted input. The next line of input is then taken to be the password, which
is obviously wrong.

2) The CR/LF line endings in windows is confusing the data/password input in
gpg. As I couldn't reproduce your problem in linux, I'm leaning towards this

You can try giving the password on the command line.

> gpg --passphrase test

However, I might add that I'm not able to reproduce the problem on linux and I
don't have any Windows computers at hand right now so this is just guesswork.

Einar Ryeng

More information about the Gnupg-users mailing list