Decrypt on from windows cli does not work

I try to decrypt a file, but private key could not be loaded

set GNUPGHOME=C:\opt\gpg4win\home
set GPG=C:\opt\gpg4win\bin\gpg.exe

set WORKDIR=C:\Users\zov
set GPGFILE=%WORKDIR%\in\testfile.txt.gpg
set TXTFILE=%WORKDIR%\out\testfile.txt

C:\Users\zov>%GPG% --list-signatures
C:\opt\gpg4win\home\pubring.kbx

pub ed25519 2022-06-02 [SC] [verfällt: 2027-06-02]
061B9E5A7B1BBF573B631D3B9D3BA183BD95CFC3
uid [ ultimativ ] SVC-Transfer SVC-Transfer@example.com
sig 3 9D3BA183BD95CFC3 2022-06-02 SVC-Transfer SVC-Transfer@example.com
sub cv25519 2022-06-02 [E] [verfällt: 2027-06-02]
sig 9D3BA183BD95CFC3 2022-06-02 SVC-Transfer SVC-Transfer@example.com

C:\Users\zov>echo xxxx-yyyy-zzzz | %GPG% --passphrase-fd 0 --decrypt-files %GPGFILE%
gpg: verschlüsselt mit cv25519 Schlüssel, ID F55EC63B1C649C72, erzeugt 2022-06-02
“SVC-Transfer SVC-Transfer@example.com
gpg: can’t connect to the gpg-agent: IPC “connect” Aufruf fehlgeschlagen
gpg: can’t connect to the gpg-agent: IPC “connect” Aufruf fehlgeschlagen
gpg: keydb_search failed: Agent läuft nicht
gpg: Entschlüsselung mit Public-Key-Verfahren fehlgeschlagen: Kein geheimer Schlüssel
gpg: Entschlüsselung fehlgeschlagen: Kein geheimer Schlüssel

Hello Dieter Winklmeier,

can I assume that you use the newest version of Gpg4win which is 4.0.2? Often an update can solve a problem.

If you already use the newest version maybe you can try to run \bin\gpg-connect-agent.exe to start the agent and see what happens.

Greetings,
Christoph

Hello Christoph,
sorry for the incomplete information, yes it’s version 4.0.2:
I made a portable version and installed it on our w2k19 server.

C:\Users\zov>c:\opt\gpg4win\bin\gpg-connect-agent.exe
gpg-connect-agent: Kein aktiver gpg-agent - `c:\opt\gpg4win\bin\gpg-agent.exe’ wird gestartet
gpg-connect-agent: Warte bis der gpg-agent bereit ist … (5s)
gpg-connect-agent: Warte bis der gpg-agent bereit ist … (4s)
gpg-connect-agent: Warte bis der gpg-agent bereit ist … (3s)
gpg-connect-agent: Warte bis der gpg-agent bereit ist … (2s)
gpg-connect-agent: Warte bis der gpg-agent bereit ist … (1s)
gpg-connect-agent: can’t connect to the gpg-agent: IPC “connect” Aufruf fehlgeschlagen
gpg-connect-agent: Fehler beim Senden der Standardoptionen: Agent läuft nicht

I made a test with the full version:

C:\Users\zov>“c:\Program Files (x86)\GnuPG\bin\gpg-connect-agent.exe” --verbose
gpg-connect-agent: Kein aktiver gpg-agent - `c:\Program Files (x86)\GnuPG\bin\gpg-agent.exe’ wird gestartet
gpg-connect-agent: Warte bis der gpg-agent bereit ist … (5s)
gpg-connect-agent: Verbindung zum gpg-agent aufgebaut

^c

I verify if one of the dll etc. is missing and send you an update.

I copied all files from C:\Program Files (x86\GnuPG to my C:\opt\GnuPG

mkdir work
cd work
set GPGDIR=C:\opt\gpg4win
set GNUPGHOME=C:\opt\gpg4win\home
set GPG=%GPGDIR%\bin\gpg.exe
set WORKDIR=C:\Users\zov\work

set TXTFILE=%WORKDIR%\testfile.txt
set DECRYPTKEYFILE=%WORKDIR%\key.txt

set PGPFILE=%WORKDIR%\testfile.txt.pgp

%GPG% --list-keys
C:\opt\gpg4win\home\pubring.kbx

pub ed25519 2022-06-02 [SC] [expires: 2027-06-02]
061B9E5A7B1BBF573B631D3B9D3BA183BD95CFC3
uid [ultimate] SVC-Transfer SVC-Transfer@example.com
sub cv25519 2022-06-02 [E] [expires: 2027-06-02]

echo “It’s working” > testfile.txt

echo xxx-yyy-zzz > key.txt

%GPG% -r SVC-Transfer --always-trust --batch --output %PGPFILE% --encrypt %TXTFILE%

%GPG% --batch --yes --passphrase-file %DECRYPTKEYFILE% --output new.txt --decrypt %PGPFILE%
gpg: encrypted with cv25519 key, ID F55EC63B1C649C72, created 2022-06-02
“SVC-Transfer SVC-Transfer@example.com

===>> GUI for Password !!!

C:\Users\zov\work>type new.txt
“It’s working”

C:\Users\zov\work>type %DECRYPTKEYFILE%
xxyx-yyyy-zzz

I can’t get it interactive …

You mean you can’t get it NON-interactive don’t you? :slight_smile: Please try to use the parameter + argument “–pinentry-mode loopback” instead of “–yes”. Does that solve the problem?

yes, NON-Interactive, sorry again.

Now it’s working:

C:\Users\zov\work>%GPG% --batch --pinentry-mode loopback --passphrase-file %DECRYPTKEYFILE% --output new.txt --decrypt %PGPFILE%
gpg: encrypted with cv25519 key, ID F55EC63B1C649C72, created 2022-06-02
“SVC-Transfer SVC-Transfer@example.com

C:\Users\zov\work>type new.txt
“It’s working”

Thank you very much.

“yes, NON-Interactive, sorry again.”
You don’t have to apologize :slight_smile: I just wanted to be sure. It could be that I misunderstood you.

“Thank you very much.”
I’m glad that we could find the solution!