« Return to Thread: Development problem with passphrase-fd

Development problem with passphrase-fd

by Brian Lee :: Rate this Message:

Reply to Author | View in Thread

I am working on an application that works by spawning GPG command line, using the passphrase-fd feature.  The problem is that these commands worked fine when I tested them in DOS command prompt, but did not work in my program using CreateProcess.  I tried both the "echo passphrase" and the "redirect from passphrase file" approaches, but none of them worked.  I wonder if I could use CreateProcess, or there is a better way.  Any suggestions would be appreciated.

Here is the code of my test program on Windows XP:
=================================================
#include "stdafx.h"
#include <stdio.h>
#include <atlstr.h>  
#include <TCHAR.H>

//-------------------------------------------------------------
HANDLE LaunchViaCreateProcess(LPCTSTR program, LPCTSTR sCommand)
{
        HANDLE hProcess = NULL;
        PROCESS_INFORMATION processInfo;
        ZeroMemory(&processInfo, sizeof(processInfo));
        STARTUPINFO startupInfo;
        ZeroMemory(&startupInfo, sizeof(startupInfo));
        startupInfo.cb = sizeof(startupInfo);

        if (CreateProcess(  (LPCTSTR)program,  
                              (LPTSTR)sCommand,
                        NULL, NULL, FALSE, 0, NULL, NULL,
                        &startupInfo,
                        &processInfo))
        {
                hProcess = processInfo.hProcess;
                printf("SUCCESS\n");
        }
        else
        {
                printf("ERROR = %d \n", GetLastError());
        }
        return hProcess;
}



//----------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
        HANDLE hProcess;
        LPTSTR sCommand;

        //sCommand = _tcsdup(TEXT("echo mypass| gpg --passphrase-fd 0 --output testfile.txt --decrypt testfile.txt.gpg"));

        sCommand = _tcsdup(TEXT("gpg --batch --passphrase-fd 0 --output testfile.txt --decrypt testfile.txt.txt.gpg < mypass.txt"));

         hProcess = LaunchViaCreateProcess( NULL,  sCommand);  

     return 0;
}
=================================================
Thanks in advance.
Brian Lee

 « Return to Thread: Development problem with passphrase-fd