Openssl签名与在VB.Net中创建的批处理文件

时间:2018-12-11 09:18:38

标签: vb.net batch-file openssl

试图制作一个对.zip文件签名的批处理文件,我发疯了。

我从以下Openssl命令行开始:

openssl smime -sign –in <original_file_path> –outform der –binary –nodetach -out <signed_file_path> -signer <file_PEM_path> -passin pass:<file_PEM_password>

然后我在VB.Net中实现了.bat文件的创建:

Private Sub Firma_File(ByVal openssl_path As String, ByVal myFile_path As String, ByVal signedFile_path As String, ByVal key_path As String, ByVal myPassword As String, ByVal myBatch_path As String)
    Dim sb As New StringBuilder
    sb.AppendLine("@echo off")
    sb.AppendLine("cls")
    sb.AppendLine("set var_openssl=" & openssl_path & "")
    sb.AppendLine("set var_myFile=" & myFile_path & "")
    sb.AppendLine("set var_signedFile=" & signedFile_path & "")
    sb.AppendLine("set var_Key=" & key_path & "")
    sb.AppendLine("set var_password=" & myPassword & "")
    sb.AppendLine("cd %var_openssl%")
    sb.AppendLine("openssl smime -sign –in %var_myFile% –outform der –binary –nodetach -out %var_signedFile% -signer file %var_Key% -pass pass:%var_password%")

    File.WriteAllText(myBatch_path, sb.ToString())

    Dim psi As New ProcessStartInfo(myBatch_path)
    psi.RedirectStandardError = True
    psi.RedirectStandardOutput = True
    psi.CreateNoWindow = False
    psi.WindowStyle = ProcessWindowStyle.Hidden
    psi.UseShellExecute = False

    Dim process As Process = Process.Start(psi)
End Sub

结果.bat文件包含(从Notepad ++复制):

@echo off
cls
set var_openssl=C:\DATA\OpenSSL\bin
set var_myFile=C:\Users\AlessandroT-gvs\Desktop\File origine\FI.12345678901.2018345.0947.001.zip
set var_signedFile=C:\Users\AlessandroT-gvs\Desktop\File origine\FI.12345678901.2018345.0947.001.zip.p7m
set var_Key=C:\CERTS\FIRMA.PEM
set var_password=gvs2018!
cd %var_openssl%
openssl smime -sign –in %var_myFile% –outform der –binary –nodetach -out %var_signedFile% -signer file %var_Key% -pass pass:%var_password%

最后启动.bat文件,响应为:

No signer certificate specified

如果我尝试在Openssl中复制相同的命令字符串,它将起作用。 我做错了什么? Alredy在路径上使用了双引号,但没有成功。

0 个答案:

没有答案