Solved

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

Posted on 2006-11-19
16
4,304 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Each year, investment in cloud platforms grows more than 20% (https://www.immun.io/hubfs/Immunio_2016/Content/Marketing/Cloud-Security-Report-2016.pdf?submissionGuid=a8d80a00-6fee-4b85-81db-a4e28f681762) as an increasing number of companies begin to…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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