Solved

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

Posted on 2006-11-19
16
4,633 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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
 
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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
Recovering from what the press called "the largest-ever cyber-attack", IT departments worldwide are discussing ways to defend against this in the future. In this process, many people are looking for immediate actions while, instead, they need to tho…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

691 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