在我的PC上,通过“开始”按钮运行此工具,一切正常。当我生成可执行文件并将可执行文件复制到生产盒中并通过生产计算机上的SQL Server代理计划作业时,一切正常,可以创建文件,但是加密位不起作用。 生产服务器上的gpg.exe位于:\ sql2014 \ c $ \ Program Files(x86)\ GnuPG \ bin
gpg在我的PC上:C:\ Program Files(x86)\ GnuPG \ bin
在正确的位置创建了filename.csv,好了-我用这两个名称进行了测试 Dim Extract_File As String =“ \ sql2014 \ e $ \ Extracts \ ProgramName \ filename.csv” ‘Dim Extract_File As String =“ E:\ Extracts \ ProgramName \ filename.csv”‘从我的PC上执行此操作,我必须将E:更改为C:
此行调用该函数: FileEncrypted = Encrypt_File(Extract_File,Batch_Timestamp)
Private Function Encrypt_File(File_To_Encrypt As String, Batch_Timestamp As Date)
On Error GoTo Encrypt_File_Error
Dim Success As Boolean = False
Dim sourceName As String = File_To_Encrypt
Dim gpgProcess = New Process()
‘Test with working directory - no effect
‘gpgProcess.StartInfo.UseShellExecute = False
'gpgProcess.StartInfo.WorkingDirectory = "\\sql2014\c$\Program Files (x86)\GnuPG\bin\"
‘gpgProcess.StartInfo.FileName = "gpg.exe"
gpgProcess.StartInfo.FileName = \\sql2014\c$\Program Files (x86)\GnuPG\bin\gpg.exe ‘This works from my PC
‘gpgProcess.StartInfo.FileName = \\sql2014\c$\Program Files (x86)\GnuPG\bn\gpg.exe ‘If I change this path took the “i” out of bin I get an error: The system cannot find the file specified
gpgProcess.StartInfo.UseShellExecute = False
gpgProcess.StartInfo.CreateNoWindow = True
gpgProcess.StartInfo.Arguments = "--batch --yes --recipient reciptname --encrypt " & sourceName
gpgProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
gpgProcess.Start()
gpgProcess.WaitForExit()
If FileExists(sourceName & ".gpg") Then
Success = True
End If
Encrypt_File_Exit:
On Error Resume Next
‘gpgProcess.WaitForExit() moved this up to
gpgProcess.Close()
Return Success
Exit Function
Encrypt_File_Error:
Error_Handler("SomeModule.vb", "Encrypt_File", Err, System_Output, Batch_Timestamp)
Resume Encrypt_File_Exit
End Function
有关如何解决此问题的任何建议。当它在我的PC上运行时,它将在filename.csv所在的目录中创建filename.csv.gpg。在生产服务器上,它不会创建gpg,也不会给出可见的错误消息。
答案 0 :(得分:0)
这就是我解决此问题的方法。我从NuGet软件包管理器安装了OpenPgpLib,并重新编写了此函数,如下所示。 我使用Kleopatra工具创建了.asc文件,并将其保存在下面代码位的pubkey中使用的位置。 OpenPgp来自软件包。
Private Function Encrypt_File(File_To_Encrypt As String, Log_File As String, Batch_Timestamp As Date)
Dim Success As Boolean = False
Dim encryptthis As String = File_To_Encrypt
Dim thisencrypted As String = File_To_Encrypt & ".gpg"
Dim pubkey As String = "\\sql2014\c$\Data_Programs\MyDirectory\<thepublickeyfile>.asc"
Try
OpenPgp.EncryptFile(encryptthis, thisencrypted, pubkey, False, False)
If FileExists(thisencrypted) Then
Success = True
End If
Catch ex As Exception
App_Logger(Log_File, ex.StackTrace.ToString(), System_Output, Batch_Timestamp)
Success = False
End Try
Return Success
End Function