Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

GPG decryption via script?

jasonp45 (Programmer)
9 Nov 09 9:02
I have a PGP-encrypted file which I download and decrypt on my machine (currently via the GPG Windows GUI). Call the file 'MyFile.gpg'.

I want to automate the decryption of this file. However I can't seem to locate a reference detailing the command-line syntax necessary, though I did find the manual here: http://www.gnupg.org/documentation/manuals/gnupg/.

I'm not sure what the parameters mean or how to structure the statement I'll need. First, is there a reference online simply outlining the command-line syntax for GPG under Windows (the manual I linked seems to be for Linux)?

Second, what is the exact syntax I'd use to decrypt 'C:\MyFile.gpg' to 'C:\MyDecryptedFile.xxx'? How do I point toward my private key? I will ultimately wrap this in a VBScript and will pass my passphrase via an InputBox.

Thanks!
Trevoke (Programmer)
9 Nov 09 12:19
Well, that's really a question about GPG, not about VBS, isn't it? :)
First things first.. As I don't use GPG on Windows, first we need to make sure the command-line syntax is similar.

Can you do this?
c:\>...\>gpg --help

And get a help output, or do you get an error? Do of course replace 'gpg' with the name of the actual command-line executable..

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?

jasonp45 (Programmer)
9 Nov 09 13:15
Yeah I suppose it is more appropriately a GPG question, though I'm not sure if there's a forum for that?

However my thought was that if anyone had implemented it via command-line they'd do so via either VBScript or a DOS batch file, and since I'm doing the former this seemed the place to post.

Yes, the 'help' syntax you posted works; thanks.

From the GPG directory I ran "gpg -d "C:\MyFile.pgp". It prompted me for my passphrase, then decrypted the file in the command-window.

Not sure from the help items how to:
a) Send the passphrase as a parameter
b) Send the decrypted output to a file
jasonp45 (Programmer)
9 Nov 09 13:19
I got it to output to a file like so:

"C:\Program Files\GNU\GnuPG\gpg.exe" -d "C:\MiFile.pgp" > "C:\MyFile.txt"

Now the only piece of the puzzle is passing the passphrase as a parameter via command-line.
Trevoke (Programmer)
9 Nov 09 15:18
Yeah, and that's really kinda tricky, since that's really the bit that makes GPG secure.. winky smile You might be able to make GPG somehow wait for input and use some Windows trick to pipe whatever you type into the command line?
On this particular bit, I am out of my league.

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?

jasonp45 (Programmer)
9 Nov 09 15:55
Got it!

This is the command-line syntax:
"C:\Program Files\GnuPG\gpg.exe" --passphrase "My passphrase" -o "C:\MyFile.txt" -d "C:\MyFile.pgp"

Here is a VBScript example:

CODE

Option Explicit

Dim bWaitOnReturn: bWaitOnReturn = True
Dim iWindowStyle: iWindowStyle = 7 'Minimized; active window stays active
Dim sPassphrase: sPassphrase = InputBox("Enter passphrase","Passphrase")
Dim sFileName_Output: sFileName_Output = "C:\MyDecryptedFile.txt"
Dim sFileName_Input: sFileName_Input = "C:\MyEncryptedFile.pgp"
Dim sCommand_Text: sCommand_Text = Chr(34) & "C:\Program Files (x86)\GNU\GnuPG\gpg.exe" & Chr(34) & "--passphrase " & Chr(34) & sPassphrase & Chr(34) & " -o " & Chr(34) & sFileName_Output & Chr(34) & " -d " & Chr(34) & sFileName_Input & Chr(34)
Dim oWiSH_Shell: Set oWiSH_Shell = CreateObject("WScript.Shell")
oWiSH_Shell.Run sCommand_Text, iWindowStyle, bWaitOnReturn
Set oWiSH_Shell = Nothing
WScript.Quit

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close