Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


GPG decryption via script?

GPG decryption via script?

GPG decryption via script?

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.


RE: GPG decryption via script?

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?

RE: GPG decryption via script?

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

RE: GPG decryption via script?

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.

RE: GPG decryption via script?

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?

RE: GPG decryption via script?

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:


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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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!

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