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:\#SystemResearch\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 FunctionEnd Class
