GPG problem with passphrase

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jatinvmehta
    New Member
    • Mar 2008
    • 6

    #1

    GPG problem with passphrase

    ProcessStartInf o psi = new ProcessStartInf o("cmd.exe");

    psi.CreateNoWin dow = false;

    psi.UseShellExe cute = false;

    psi.RedirectSta ndardInput = true;

    psi.RedirectSta ndardOutput = true;

    psi.RedirectSta ndardError = true;

    psi.WorkingDire ctory = "C:";

    System.Diagnost ics.Process process = System.Diagnost ics.Process.Sta rt(psi);

    string sCommandLine = "echo test| gpg -es --passphrase-fd 0 --recipient jatinvmehta@gma il.com -o c:\test.gpg c:\test.txt";

    process.Standar dInput.WriteLin e(sCommandLine) ;

    process.Standar dInput.Flush();

    process.Standar dInput.Close();

    process.WaitFor Exit();

    process.Close() ;



    Same command run succesfully from commandline. I don't understand what is the problem.



    Thanks in advance.
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    What error are you getting, what line of code is this failing at? If you don't tell us exactly what's wrong, there's no way anyone can help fix it...

    Comment

    • jatinvmehta
      New Member
      • Mar 2008
      • 6

      #3
      Originally posted by balabaster
      What error are you getting, what line of code is this failing at? If you don't tell us exactly what's wrong, there's no way anyone can help fix it...
      Hi Bala, i don't get any error. When i run the application, nothing happen and if i say
      psi.CreateNoWin dow = false;

      It opens command window with following text

      Reading passphrase from file descriptor 0

      That's it.

      Comment

      • balabaster
        Recognized Expert Contributor
        • Mar 2007
        • 798

        #4
        That's all you're telling it to do... if you take everything that's between the quotes from your command and paste it into the command window, what does it do?

        Comment

        • jatinvmehta
          New Member
          • Mar 2008
          • 6

          #5
          Originally posted by balabaster
          That's all you're telling it to do... if you take everything that's between the quotes from your command and paste it into the command window, what does it do?
          if i open command window by start --> run --> cmd and type following line

          echo test| gpg -es --passphrase-fd 0 --recipient jatinvmehta@gma il.com -o c:\test.gpg c:\test.txt

          I runs fine and create test.gpg.

          Now, i have c# application and when i run same command by opening cmd.exe, it doesn't work.

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            Did you mean to do something like this?
            Code:
            string sCommandLine = "echo test| gpg -es --passphrase-fd 0 --recipient jatinvmehta@gmail.com -o c:\test.gpg c:\test.txt";
            ProcessStartInfo psi = new ProcessStartInfo(sCommandLine);
            psi.CreateNoWindow = true;
            psi.UseShellExecute = false;
            psi.RedirectStandardOutput = true;
            psi.WorkingDirectory = "C:";
            System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
            string output = process.StandardOutput.ReadToEnd();
            MessageBox.Show(output);
            process.WaitForExit();
            process.Close();

            Comment

            • jatinvmehta
              New Member
              • Mar 2008
              • 6

              #7
              Originally posted by balabaster
              Did you mean to do something like this?
              Code:
              string sCommandLine = "echo test| gpg -es --passphrase-fd 0 --recipient jatinvmehta@gmail.com -o c:\test.gpg c:\test.txt";
              ProcessStartInfo psi = new ProcessStartInfo(sCommandLine);
              psi.CreateNoWindow = true;
              psi.UseShellExecute = false;
              psi.RedirectStandardOutput = true;
              psi.WorkingDirectory = "C:";
              System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
              string output = process.StandardOutput.ReadToEnd();
              MessageBox.Show(output);
              process.WaitForExit();
              process.Close();
              No, my c# application is window service. It takes file from directory encrypt it and store it on directory

              Comment

              • balabaster
                Recognized Expert Contributor
                • Mar 2007
                • 798

                #8
                Originally posted by jatinvmehta
                No, my c# application is window service. It takes file from directory encrypt it and store it on directory
                Well...the code I posted will execute your command line...it dumps the output to a message box, but if you remove the two lines pertaining to the output itself, then you should find that the code actually executes the command line you specified.

                Comment

                • jatinvmehta
                  New Member
                  • Mar 2008
                  • 6

                  #9
                  Originally posted by balabaster
                  Well...the code I posted will execute your command line...it dumps the output to a message box, but if you remove the two lines pertaining to the output itself, then you should find that the code actually executes the command line you specified.
                  Hi, ProcessStartInf o expect file name. If i run with your code, it stops at ReadToEnd() function for unlimited time.

                  Comment

                  • balabaster
                    Recognized Expert Contributor
                    • Mar 2007
                    • 798

                    #10
                    [Code=C#]string sCommandLine = "echo test| gpg -es --passphrase-fd 0 --recipient jatinvmehta@gma il.com -o c:\test.gpg c:\test.txt";
                    ProcessStartInf o psi = new ProcessStartInf o(sCommandLine) ;[/Code]

                    These two lines of code assign a command to ProcessStartInf o. You don't need the ReadToEnd() because you're not actually outputting the response to screen. The command line creates the file so you don't need any other output.

                    Delete lines 8 and 9 of the code I posted if you're running as a Windows Service as it is irrelevant.

                    Comment

                    Working...