1
gpg: AES256 encrypted data                      
gpg: encrypted with 1 passphrase                                                   
gpg: decryption failed: Bad session key

I am doing decryption by following command:

gpg --passphrase-file /path/to/key --output /path/to/output --decrypt /path/to/file

It again asks for the passphrase and results in above mentioned error.

When I fed this error to a search engine, I encountered many questions which mentioned the last line 'Bad session key' and most of their answers said it may be because encryption was done by GnuPG version 1 and decryption is done by GnuPG version 2. However, in this case both the version are 2, and also I didn't find this exact same error in any question.

I am doing this on Termux on android.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
user573082
  • 31
  • 3

1 Answers1

2

I have encountered this error when using the wrong password to decrypt a file with GPG. I recommend checking the passphrase file to be sure that you have the correct content and ONLY the correct content, no extra spaces or newline characters. Also ensure that the read permission for the file is granted to your user, as that may also be a possible cause of the problem.

If that doesn't work, try adding the --batch --pinentry-mode loopback flags before --passphrase-file, so the resulting command in your case would look like the following:

gpg --batch --pinentry-mode loopback --passphrase-file /path/to/key --output /path/to/output --decrypt /path/to/file

For more information about the flags in question, see this answer and the rest of the attached thread.

ajmeese7
  • 244