gpg is doing the wrong thing (I claim) regarding carriage returns and new lines \r\n in passphrase files in Windows.
If you create a passphrase file in Windows you can easily end up with \r\n at the end of the line. gpg seems to be ignoring the \n but leaving the \r as part of the passphrase, leading to confusion.
Here is my version info today 2021/07/31:
gpg (GnuPG) 2.2.28
libgcrypt 1.8.8
Version Gpg4win-3.1.16
I am using Windows 7 with mingw as the command line.
In writing a script to automate the encryption processfor a bunch of files, here was the first test with a single file:
% gpg --batch --passphrase-file ppfile.txt -c myfile.txt
ppfile.txt contained one line:1234
When I tried to use Kleopatra to decrypt the file I got:
gpg: AES.CFB encrypted data
gpg: encrypted with 1 passphrase
gpg: AllowSetForegroundWindow(4264) failed: Access is denied.
gpg: decryption failed: Bad session key
Here is the hexdump output of ppfile.txt:
00000000- 31 32 33 34 0D 0A [1234.. ]
So is my passphrase 1234\r\n? No. It seems to be "1234\r". This worked:
% gpg --batch --passphrase $'1234\r' --decrypt myfile.txt.gpg > myfile-decrypted.txt
If gpg is going to ignore the \n it would seem appropriate to also ignore \r.