Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GPG command-line on Windows

Status
Not open for further replies.

jasonp45

Programmer
Aug 23, 2001
212
0
0
US
I'm trying to decrypt a GPG/PGP file using GPG via the command line.

This works:
"C:\Program Files\GnuPG\gpg.exe" -o "C:\MyFile.txt" -d "C:\MyEncryptedFile.pgp"

However the command-window prompts me for my passphrase.

I plan on scripting this and calling an InputBox to prompt for the passphrase entry. Right now I'm trying to put the passphrase as a literal string parameter on the command-line using various options but I can't get it to work.

I've read about invoking the gpg-agent and pre-loading a passphrase in the documentation but I can't seem to figure out the details.
 
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\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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top