vb.net&命令行:使用GnuPG解密的路径中的空格(vb.net & command line: spaces in path to decrypt with GnuPG)

编程入门 行业动态 更新时间:2024-10-27 06:28:21
vb.net&命令行:使用GnuPG解密的路径中的空格(vb.net & command line: spaces in path to decrypt with GnuPG)

我一直在努力解决这个问题。 我试图使用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

更多推荐

本文发布于:2023-07-26 19:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:空格   命令行   路径   GnuPG   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!