Solved

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

Posted on 2006-11-19
16
4,548 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many businesses neglect disaster recovery and treat it as an after-thought. I can tell you first hand that data will be lost, hard drives die, servers will be hacked, and careless (or malicious) employees can ruin your data.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
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…

734 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