Reputation: 39
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
Upvotes: 1
Views: 1081
Reputation: 17647
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
Upvotes: 2