Multiple File Encryption (Win32)
Leigh S. Jones
kr6x@kr6x.com
Wed Apr 10 16:16:01 2002
This is a multi-part message in MIME format.
------=_NextPart_000_016E_01C1E060.772266B0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I don't have time to test this right now, but my memory says that the =
following lines of code
worked right. I later rewrote them and will send them to you in the =
complete version later.
The rewrite performed a great deal of error checking and assured that =
the file containing=20
the password was first overwritten with new data then deleted.
This code was written as a Win32 console application in Borland C++. I =
don't
think that the code should need much change to work with MSVC. Your =
batch
file would call this program after collecting your password from you, =
this program
proceeds by first writing a file named "command" that contains your =
passphrase. =20
I used low level file I/O commands for the most part, the objective was =
to accomodate=20
the "_get_osfhandle()" function's needs, but some later update will use =
the low level=20
file I/O motif to take possession of the "command" file for security =
purposes. As written,=20
argument 1 contains the name of the file to be decrypted, argument 2 =
contains the user=20
name, argument 3 contains the passphrase. Don't use this on a computer =
that you don't
have 100% physical control over and always change your secret key =
password after
running this code.
Oh, yes, as written the code "signs" files, you'd rewrite this for =
purposes of decryption.=20
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <string.h>
int main ( int argc, char *argv[ ] )
{
int command;
FILE *ptr;
char buf[ 1024 ];
if ( argc !=3D 4 )
{
return -1;
} /* end if ( argc !=3D 4 ) */
command =3D open ( "command", O_WRONLY );
write ( command, argv[ 3 ], strlen ( argv[ 3 ] ) );
close ( command );
command =3D open ( "command", O_RDONLY );
sprintf ( buf,
"gpg --passphrase %d -u %s --batch --clearsign %s",
_get_osfhandle ( ( int ) command ),
argv[ 2 ],
argv[ 1 ] );
ptr =3D _popen ( buf, "rt" );
while ( !feof ( ptr ) ) fgets ( buf, sizeof ( buf ), ptr );
_pclose ( ptr );
close ( command );
command =3D open ( "command", O_TRUNC );
close ( command );
return ( 0 );
} /* end main ( ) */
----- Original Message -----=20
From: AthlonRob=20
To: gnupg-users@gnupg.org=20
Sent: Tuesday, April 09, 2002 5:45 PM
Subject: Multiple File Encryption (Win32)
Hi all-
I'm trying to come up with a way to encrypt batches of files... 10-15 =
at most with varying file names. I want the files to be encrypted into =
either a single large file or in to multiple files, each replacing the =
non-encrypted version. The files are *NOT* ASCII text. I want to then =
be able to decrypt each of them to the original state with a single =
command (batch file)
Now... after searching around the web for a while, I'm not having much =
luck. Any thoughts? I've got GnuPG downloaded and working. I'm =
running Windows XP... so this is a Win32 thing.
Rob
------=_NextPart_000_016E_01C1E060.772266B0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2712.300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I don't have time to test this right =
now, but my=20
memory says that the following lines of code</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>worked right. I later rewrote =
them and will=20
send them to you in the complete version later.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>The rewrite performed a great deal of =
error=20
checking and assured that the file containing </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>the password was first overwritten with =
new data=20
then deleted.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>This code was written as a Win32 =
console=20
application in Borland C++. I don't</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>think that the code should need much =
change to work=20
with MSVC. Your batch</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>file would call this program after =
collecting your=20
password from you, this program</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>proceeds by first writing a file named =
"command"=20
that contains </FONT><FONT face=3DArial size=3D2>your passphrase. =20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>I used low level file I/O commands for =
the most=20
part, the </FONT><FONT face=3DArial size=3D2>objective was to accomodate =
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>the "_get_osfhandle()" function's =
needs,=20
but </FONT><FONT face=3DArial size=3D2>some later update will use =
the low level=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>file I/O motif to take possession of =
the=20
</FONT><FONT face=3DArial size=3D2>"command" file for security =
purposes. As=20
written, </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>argument 1 contains the </FONT><FONT =
face=3DArial=20
size=3D2>name of the file to be decrypted, argument 2 contains the user=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>name, argument 3 contains the =
passphrase. =20
Don't use this on a computer that you don't</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>have 100% physical control over and =
always=20
change your secret key password after</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>running this code.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>Oh, yes, as written the code "signs" =
files, you'd=20
rewrite this for purposes of decryption.</FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>#include <stdlib.h><BR>#include=20
<stdio.h><BR>#include <fcntl.h><BR>#include =
<io.h><BR>#include=20
<string.h></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>int main ( int argc, char *argv[ ] =
)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> {<BR> int =
command;<BR> FILE=20
*ptr;<BR> char buf[ 1024 ];</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> if ( argc !=3D 4=20
)<BR> {<BR> return -1;<BR> } /* end if =
( argc=20
!=3D 4 ) */<BR> command =3D open ( "command", O_WRONLY =
);<BR> write (=20
command, argv[ 3 ], strlen ( argv[ 3 ] ) );<BR> close ( command=20
);<BR> command =3D open ( "command", O_RDONLY );<BR> sprintf ( =
buf,<BR> "gpg --passphrase %d -u %s --batch =
--clearsign=20
%s",<BR> _get_osfhandle ( ( int ) command=20
),<BR> argv[ 2 ],<BR> =
argv[ 1 ]=20
);<BR> ptr =3D _popen ( buf, "rt" );<BR> while ( !feof ( ptr ) =
) fgets (=20
buf, sizeof ( buf ), ptr );<BR> _pclose ( ptr =
);<BR> close (=20
command );<BR> command =3D open ( "command", O_TRUNC =
);<BR> close (=20
command );<BR> return ( 0 );<BR> } /* end main ( ) =
*/</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
<DIV=20
style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
<A title=3Dathlonrobnf@cs.com =
href=3D"mailto:athlonrobnf@cs.com">AthlonRob</A>=20
</DIV>
<DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dgnupg-users@gnupg.org=20
href=3D"mailto:gnupg-users@gnupg.org">gnupg-users@gnupg.org</A> </DIV>
<DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Tuesday, April 09, 2002 =
5:45=20
PM</DIV>
<DIV style=3D"FONT: 10pt arial"><B>Subject:</B> Multiple File =
Encryption=20
(Win32)</DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2></FONT><BR></DIV>
<DIV><FONT face=3DArial size=3D2>Hi all-</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>I'm trying to come up with a way to =
encrypt=20
batches of files... 10-15 at most with varying file names. I =
want the=20
files to be encrypted into either a single large file or in to =
multiple files,=20
each replacing the non-encrypted version. The files are *NOT* =
ASCII=20
text. I want to then be able to decrypt each of them to the =
original=20
state with a single command (batch file)</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Now... after searching around the web =
for a=20
while, I'm not having much luck. Any thoughts? I've got =
GnuPG=20
downloaded and working. I'm running Windows XP... so this is a =
Win32=20
thing.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial =
size=3D2>Rob</FONT></DIV></BLOCKQUOTE></BODY></HTML>
------=_NextPart_000_016E_01C1E060.772266B0--