Page MenuHome GnuPG

NEWBIE: Command Line decrypt
Closed, InvalidPublic

Description

Good morning. I am new to GNUPG and I am attempting to create a .net function
which will take a given location path and filename and decrypt it to a given
location path and name. The code does not error but it also does not create the
decrypt the file.

Here is my code:

Public Class Form1

Property _Passphrase As String = "PHEAA1PASSHE"
Public Function GetDecryptedFilename() As FileInfo
    Return My.Computer.FileSystem.GetFileInfo("F:\#System

Research\Cheyney\State Grant\State Grant Transmissions\SG17STAT_01062017.215116")

End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs)

Handles Button1.Click

        Dim myfilename As String = DecryptFile(GetDecryptedFilename)
        Stop
    End Sub

    Private Function DecryptFile(encryptedFile As FileInfo) As String
        ' decrypts the file using GnuPG, saves it to the file system
        ' and returns the new (decrypted) file name.

        ' encrypted file: thefile.xml.gpg decrypted: thefile.xml

        Dim outputFileName As String = "FRED.out"
        ' whatever you want here - just a convention

        Dim path As String = encryptedFile.DirectoryName
        Dim outputFileNameFullPath As String = Convert.ToString(path &

Convert.ToString("\")) & outputFileName

        Try
            Dim psi As New System.Diagnostics.ProcessStartInfo("cmd.exe")
            psi.CreateNoWindow = False
            psi.UseShellExecute = False
            psi.RedirectStandardInput = True
            psi.RedirectStandardOutput = True
            psi.RedirectStandardError = True
            psi.WorkingDirectory = "C:\Program Files (x86)\Gnu\GnuPG"

            Dim process As System.Diagnostics.Process =

System.Diagnostics.Process.Start(psi)

' actually NEED to set this as a local string variable
' and pass it - bombs otherwise!
Dim sCommandLine As String = (Convert.ToString("echo " +

Me._passphrase + "| gpg.exe --passphrase-fd 0 -o """) & outputFileNameFullPath) +
""" --decrypt """ + encryptedFile.FullName + """"

        process.StandardInput.WriteLine(sCommandLine)
        process.StandardInput.Flush()
        process.StandardInput.Close()
        process.WaitForExit()
        process.Close()
    Catch ex As Exception
        'Me.HandleError(ex)
    End Try
    Return outputFileName
End Function

End Class

Details

Due Date
Jan 17 2017, 1:00 AM
Version
2.2.0

Event Timeline

justus lowered the priority of this task from High to Normal.Jan 16 2017, 10:56 AM
justus removed projects: Bug Report, gpa.
justus added a project: gnupg.
justus added a subscriber: justus.

This is a bug tracker, not a support forum. If you need commercial support for
GnuPG, we are happy to provide that.

If you want to use GnuPG in your application, it is *strongly* recommended to
use GPGME. Please see https://wiki.gnupg.org/APIs

justus claimed this task.