Solved

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

Posted on 2006-11-19
16
4,072 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
well i couldnt find it either :)
0
 

Author Comment

by:miken05
Comment Utility
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
Comment Utility
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
Comment Utility
http://lists.gnupg.org/pipermail/gnupg-users/2005-February/024643.html

take a look at this link too..

gpg --multifile --encrypt tobeencrypted\*
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Expert Comment

by:data_grrr
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
--multifile is the guy I am looking for mate, thanks a lot, full points to you sir!
0
 
LVL 3

Expert Comment

by:mahe2000
Comment Utility
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
Comment Utility
need to automate it.
0
 
LVL 1

Expert Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

SHARE your personal details only on a NEED to basis. Take CHARGE and SECURE your IDENTITY. How do I then PROTECT myself and stay in charge of my own Personal details (and) - MY own WAY...
Even if you have implemented a Mobile Device Management solution company wide, it is a good idea to make sure you are taking into account all of the major risks to your electronic protected health information (ePHI).
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

12 Experts available now in Live!

Get 1:1 Help Now