Solved

How can I automate GPG on multiple files within a directory?

Posted on 2006-11-19
16
4,198 Views
Last Modified: 2008-03-10
Hi I have several encrypted files that are uploaded to us each day using GPG.
I need to write a program or script to take each of these files and unencrypt them using GPG into a different folder for processing and remove the the encrypted ones from the original upload folder.

THen once they are processed there will be unencrypted logs about what happened during the process, I then need to take each of these files and place them into the upload folder as encrypted text files and then delete the original plaintext ones.

I have played around with c# and the Process.Start method, but this has had very mixed results. I've also looked for a gpg daemon or agent written for windows that I could schedule or that could monitor a directory and have had no luck.
I would think just a simple batch file would do this but my dos is not so good :| The part i am struggling with is how do you perform an action on one file at a time in dos, as in like a for each file in folder type cursor thing.

All of our servers are windows based, and I don't really want to use cygwin. So the solution needs to work in windows 2003!

I have got GPG set up with the certificates and can do this manually. Look forward to some help, I am sure this is quite simple but it's driving me nuts to max points to you if you solve it.
0
Comment
Question by:miken05
  • 10
  • 5
16 Comments
 

Author Comment

by:miken05
ID: 17976814
If there IS a nice windows program that will run as a daemon and maybe even log what it was doing that would be awesome by the way.. you get max points if you point me at a good program for this that's open source or freeware.
0
 
LVL 1

Expert Comment

by:data_grrr
ID: 17976942
it's very easy in fact.

you need a batch file.

so there are two directories. C:\A   C:\B - the crypted files are in C:\A

first create a file called gpg.bat - or whatever you want..

then click edit.

in the file type these:


cd C:\A
gpg --output doc --decrypt doc.gpg  (i don't know gpg- but you should write here *.gpg or whatever command-wildcard it is to decrypt all the files.)
copy *.* C:\A C:\B
del C:\A\*.* /Q

then save it. it should do it.




0
 

Author Comment

by:miken05
ID: 17976984
Hi, thanks, but I don't think there is a wild card to encrypt/decrypt all files in a folder, that's the point.
If I'm wrong please tell me what the syntax is.
0
 
LVL 1

Expert Comment

by:data_grrr
ID: 17977006
sorry the comment above is not complete

cd C:\A
gpg --output doc --decrypt doc.gpg  (i don't know gpg- but you should write here *.gpg or whatever command-wildcard it is to decrypt all the files.)
copy *.* C:\A C:\B  (this line copies all the files from A to B)
cd C:\the directory which holds the logs
gpg --output doc.gpg --encrypt (this must be the line you use to encrypt the logs)
copy *.* C:\the directory which holds the logs  C:\upload directory (to copy the logs to upload directory)
del C:\A\*.* /Q (this line deletes all the files in C:\A without asking)

don't use the parantheses in the batch file. this is not a complete solution but you should figure it out)
0
 
LVL 1

Expert Comment

by:data_grrr
ID: 17977009
well i couldnt find it either :)
0
 

Author Comment

by:miken05
ID: 17977012
gpg --output doc --decrypt doc.gpg  (i don't know gpg- but you should write here *.gpg or whatever command-wildcard it is to decrypt all the files.)


I don't get it, I don't think you can say --decrypt *.gpg, you need to call it file by file. Are you telling me differently or agreeing with me?
0
 
LVL 1

Expert Comment

by:data_grrr
ID: 17977047
http://www.tin.org/bin/man.cgi?section=1&topic=gpg

according to this, you can use --multifile switch with the --decrypt and --encrypt

this can process all the files at once.
0
 
LVL 1

Accepted Solution

by:
data_grrr earned 500 total points
ID: 17977060
http://lists.gnupg.org/pipermail/gnupg-users/2005-February/024643.html

take a look at this link too..

gpg --multifile --encrypt tobeencrypted\*
0
New! My Passport Wireless Pro Wi-Fi Mobile Storage

Portable wireless storage to offload, edit, and stream anywhere.

High-capacity, wireless mobile storage designed to accompany professional photographers and videographers in the field to easily offload, edit and stream captured photos and high-definition videos.

 
LVL 1

Expert Comment

by:data_grrr
ID: 17977096
ok i found it i think.

i used at my pc.

gpg --multifile --encrypt C:\A\*

this command tried to encrypy all the files in C:\A but failed. cos i dont have public key. but it must work for you.
0
 
LVL 1

Expert Comment

by:data_grrr
ID: 17977113
gpg.bat

cd C:\the directory that holds the encrypted files
gpg --multifile --decrypt C:\the directory that holds the encrypted files\*
copy *.* C:\the directory that holds the encrypted files\ C:\the process directory
cd C:\the dir. that holds logs
gpg --multifile --encrypt C:\the dir. that holds logs
copy *.* C:\upload directory
del *.* C:\the directort that holds the encrypted files
0
 
LVL 1

Expert Comment

by:data_grrr
ID: 17977126
i forgot the /Q switch for del command not to ask "are you sure"
and possibly you need other silence switches for gpg.
0
 
LVL 1

Expert Comment

by:data_grrr
ID: 17977169
gpg.bat - well above is wrong for me again.. but this must do.. :) i could erase my C:\ files :)

cd C:\the directory that holds the encrypted files
gpg --multifile --decrypt C:\the directory that holds the encrypted files\*
copy *.* C:\the directory that holds the encrypted files\ C:\the process directory
cd C:\the dir. that holds logs
gpg --multifile --encrypt C:\the dir. that holds logs
copy *.* C:\upload directory
del C:\the directory that holds the encrypted files\*.* /Q






0
 

Author Comment

by:miken05
ID: 17982625
--multifile is the guy I am looking for mate, thanks a lot, full points to you sir!
0
 
LVL 3

Expert Comment

by:mahe2000
ID: 17982756
what about using winpt (http://winpt.sourceforge.net/en/) it's a freeware tool, just drag & and drop the files you want, then tell winpt to decrytp then... and that's all folks..!!!!!
0
 

Author Comment

by:miken05
ID: 17982945
need to automate it.
0
 
LVL 1

Expert Comment

by:data_grrr
ID: 17983382
well you're welcome..let me know about automation is ok..
0

Featured Post

Superior storage. Superior surveillance.

WD Purple drives are built for 24/7, always-on, high-definition security systems. With support for up to 8 hard drives and 32 cameras, WD Purple drives are optimized for surveillance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Encryption for Business Encryption (https://en.wikipedia.org/wiki/Encryption) ensures the safety of our data when sending emails. In most cases, to read an encrypted email you must enter a secret key that will enable you to decrypt the email. T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now