我一直在努力解决这个问题。 我试图使用GnuPG解密vb.net中的文件。 如果文件路径没有空间,我可以成功解密文件。 但是当有空格时,GnuPG会返回错误。 我不知道如何用空格构造我的字符串,以便GnuPG能够处理它。
到目前为止这是我的代码..
Dim runDate As date Dim destFolder As String Dim fullName As String Dim cmdShellTemp As String destFolder = """\\srvDat\DATA\ORTSS\RECON\ASTD rem\""" fullName = runDate.ToString("yyyyMMdd") & "myFile.pdf.pgp" cmdShellTemp = "gpg --batch --passphrase """ & pgpPassphrase & """ --decrypt-files """ & destFolder & fullName & """" cmdShell = cmdShellTemp.Replace("\", "/") Shell(cmdShell)任何的想法?
谢谢
I have been struggling with this problem for some time now. I am trying to decrypt a file in vb.net using GnuPG. I am able to successfully decrypt the file if its path has NO space. However when there is a space, GnuPG returns an error. I have no idea how I should structure my string with spaces for GnuPG to be able to handle it.
This is my code so far..
Dim runDate As date Dim destFolder As String Dim fullName As String Dim cmdShellTemp As String destFolder = """\\srvDat\DATA\ORTSS\RECON\ASTD rem\""" fullName = runDate.ToString("yyyyMMdd") & "myFile.pdf.pgp" cmdShellTemp = "gpg --batch --passphrase """ & pgpPassphrase & """ --decrypt-files """ & destFolder & fullName & """" cmdShell = cmdShellTemp.Replace("\", "/") Shell(cmdShell)Any idea?
Thanks
最满意答案
编辑
查看PGP命令行文档后,它指定提供给decrpyt命令的所有文件都被视为空格分隔。 考虑到这一点,在提供整个路径时无法实现目标(除非路径不包含空格)。 您需要在包含文件的目录中启动命令提示符,并相对引用它们。
说明手册的第69页说明 :
使用PGP KMS服务器上的本地密钥或密钥解密加密文件。 如果解密的数据也被签名,则在解密过程中自动验证签名。
使用格式为: pgp --decrypt <input> [<input2> ...] [<inputd>...] [options]
哪里: <input> (必填)。 要解密的文件的空格分隔名称。
(原始答案面向字符串连接):
它应该允许路径周围的引号,即使没有空格,所以也许只是强制执行引号。 试试这个:
Dim runDate As date Dim destFolder As String Dim fullName As String Dim cmdShellTemp As String destFolder = "\\srvDat\DATA\ORTSS\RECON\ASTD rem\" '// note the removed quote marks fullName = runDate.ToString("yyyyMMdd") & "myFile.pdf.pgp" cmdShellTemp = "gpg --batch --passphrase """ & pgpPassphrase & """ --decrypt-files """ & destFolder & fullName & """" cmdShell = cmdShellTemp.Replace("\", "/") Shell(cmdShell)最终问题在于您的引号 - 您添加了两次:
destFolder = """\\srvDat\DATA\ORTSS\RECON\ASTD rem\"""会产生"\\srvDat\DATA\ORTSS\RECON\ASTD rem\"并且:
cmdShellTemp = "gpg --batch --passphrase """ & pgpPassphrase & """ --decrypt-files """ & destFolder & fullName & """"会最终得到类似的东西:
gpg --batch --passphrase "pass123" --decrpyt-files ""\\srvDat\DATA\ORTSS\RECON\ASTD rem\"20120105myFile.pdf.pgp"
这会在文件路径中产生不需要的引号
EDIT
After looking at the PGP command line documentation - it specifies that any files supplied to the decrpyt command are treated as space delimited. With this in mind you can't achieve your goal when supplying the entire path (unless the path contains no spaces). You will need to start the command prompt in the directory that contains the files instead and refer to them relatively.
Page 69 of the instruction manual states:
Decrypts encrypted files with local keys or keys on a PGP KMS server. If data being decrypted is also signed, the signature is automatically verified during the decryption process.
The usage format is: pgp --decrypt <input> [<input2> ...] [<inputd>...] [options]
Where: <input> (required). Space-separated names of the files to decrypt.
(original answer geared towards string concatenation):
It should allow quotes around the path even when there aren't spaces, so perhaps just enforce the quotation marks anyway. Try this instead:
Dim runDate As date Dim destFolder As String Dim fullName As String Dim cmdShellTemp As String destFolder = "\\srvDat\DATA\ORTSS\RECON\ASTD rem\" '// note the removed quote marks fullName = runDate.ToString("yyyyMMdd") & "myFile.pdf.pgp" cmdShellTemp = "gpg --batch --passphrase """ & pgpPassphrase & """ --decrypt-files """ & destFolder & fullName & """" cmdShell = cmdShellTemp.Replace("\", "/") Shell(cmdShell)Ultimately the issue was with your quotes - you added them twice:
destFolder = """\\srvDat\DATA\ORTSS\RECON\ASTD rem\"""would produce "\\srvDat\DATA\ORTSS\RECON\ASTD rem\" and:
cmdShellTemp = "gpg --batch --passphrase """ & pgpPassphrase & """ --decrypt-files """ & destFolder & fullName & """"would end up with something like:
gpg --batch --passphrase "pass123" --decrpyt-files ""\\srvDat\DATA\ORTSS\RECON\ASTD rem\"20120105myFile.pdf.pgp"
Which produces unwanted quotes within the file path
更多推荐
发布评论