18

I'm trying to decrypt a file using gpg and getting this error:

$ gpg --no-tty --batch --verbose --decrypt --passphrase foo file.enc
Version: GnuPG v1.4.11 (GNU/Linux)
gpg: armor header: 
gpg: CAST5 encrypted data
gpg: encrypted with 1 passphrase
gpg: decryption failed: Bad session key

I tried to reload the gpg agent, no luck:

$ gpgconf --reload gpg-agent

How to solve that?

2
  • Please add the output of gpg --list-packets < file.enc. Remove any key information you like, I'm mostly interested in the structure.
    – Jens Erat
    Commented May 19, 2015 at 7:10
  • 7
    One likely cause of this error message is that you're using the wrong passphrase. Commented Feb 17, 2019 at 6:03

4 Answers 4

23

For the record, if somebody will encounter this problem, too:

The problem was, that the encryption was done using gpg version 1.4.11 and the decryption was using gpg version 2.0.22.

After upgrading the encryption to gpg2 (2.0.17), everything worked fine.

7
  • Thanks, this was exactly my problem. Upgrading to gpg2 and renaming the alias from gpg2 to gpg resolved the issue.
    – albogdano
    Commented Feb 25, 2016 at 9:17
  • 12
    what if someone (like me) has encrypted data and needs to decrypt them? I can't update the encrypter to the same version..
    – EsseTi
    Commented Jul 27, 2018 at 11:03
  • @redjamjar I guess your only chance is to use an older version for decryption. It should be possible to install and run different gpg versions in parallel. Commented Jan 21, 2019 at 9:35
  • 4
    This is SHAMEFUL. So, I encrypt some files to keep them safe and then, 10 years from now, I won't be able to decrypt them with the very same GPG software because the encryption is VERSION-DEPENDENT and shamefully NOT BACKWARD COMPATIBLE. What??????
    – Mephisto
    Commented Dec 19, 2023 at 16:21
  • @Mephisto yes, astounding to me
    – mitchus
    Commented Jan 10 at 22:33
13

I found this, which seems to be the magic that I could not find anywhere else:

Try adding --pinentry-mode loopback to your command. Maybe there is a problem with your installation / pinentry program so that it does not start or you are accidentally using a dummy / test pinentry which provides the wrong passphrase.

1
  • 4
    The exact command that worked for me: gpg --pinentry loopback --decrypt MYFILE.gpg Commented Apr 30, 2020 at 17:54
1

I encrypted my file with a passphrase file in batch mode. When I tried to decrypt my file I got the dreaded "bad session key" message.

I created a passphrase file with Vim for Windows, and Vim left \r\n at the end of the text line even though I did not hit carriage return. gpg ignored the \n but retained the \r as part of the passphrase!

Vim for Windows can be induced to not leave \r\n, but it is easier to just use Notepad without a carriage return at the end of line. Best to check your passphrase file with a hexdump to be sure. There are other ways to get hurt by \r\n issues when supplying the passphrase using the command line, so be alert to it.

-1

I solved this problem by removing special chars like % from the password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.