Is it possible to encrypt file symmetrically with 1 (one) command line?

Aleksandar Milivojevic amilivojevic at pbl.ca
Fri Oct 1 16:40:31 CEST 2004


Chris De Young wrote:
> On Thu, Sep 30, 2004 at 11:25:33PM +0200, Oleksiy Muzalyev wrote:
> 
>>I call from VB2005:
>>
>>Shell("c:\gnupg\gpg.exe -a -c " & fileToEncrypt, AppWinStyle.NormalFocus)
>>
>>And console window opens and asks twice for the password.
>>
>>I would prefer to send the file path and password in one command.
> 
> 
> Offhand I don't know of any switches that you can use to pass the
> passphrase on the command line, though I might be missing one.  If
> it's acceptable to store the passphrase in a separate file (probably
> no more risky that coding it into a script), you could use:
> 
> gpg -a -c --batch --passphrase-fd n filename
> 
> which will read the password from file descriptor n.  0 means standard
> input, though that's not what you want in the case.

Hm, why not using 0?  I don't know how VB handles redirection of 
stdin/stdout between processes, however this works quite well in Perl on 
Unix:

#! /usr/bin/perl

$gpg_exe = "gpg";
@gpg_args = ($gpg_exe, "--quiet", "--batch", "--no-tty",
              "--passphrase-fd", "0", "-a", "-c", "blah");

open(FH, "|-") || exec @gpg_args or die "Can't execute GnuPG!";
print FH "passpharase\n";
close(FH) or die "Encryption failed!";

What this does is that it starts new gpg process, and ties its standard 
input to file handle of parent process (basically it creates a pipe 
between two processes).  Then it sends the passpharase using this pipe. 
  Note the newline at the end of passphrase.  If this can be ported to 
VB on Windows, it *should* work (tm).

P.S.
To prevent this going into the wrong direction, yes I do know that 
having passphrase in code is insecure, and yes I do know there are 
couple of nice Perl modules for handling GnuPG, and yes I do know this 
is not the best way of controlling GnuPG from another process.  This was 
just illustration, and for simple usage and with few precausions it works.

-- 
Aleksandar Milivojevic <amilivojevic at pbl.ca>    Pollard Banknote Limited
Systems Administrator                           1499 Buffalo Place
Tel: (204) 474-2323 ext 276                     Winnipeg, MB  R3T 1L7



More information about the Gnupg-users mailing list