views:

736

answers:

4

I currently have an app written in C# that can take a file and encrypt it using gpg.exe

What I'm trying to do is, instead of 1. Creating a file (from database queries usually) 2. encrypting the file 3. deleting the non-encrypted file

I want to

  1. Gather info into memory (into a dictionary or a list or whatever)
  2. stream the text/data into gpg.exe to end up with the encrypted file outputted

I've looked into pipestream, redirecting standard input to the gpg process, etc, but I haven't figured out a way to trick gpg.exe into accepting streamed text/data instead of a file on the hard drive.

Initially figured if I could do it for gpg, I could also do it for Zip as well, but I'm wondering if it's even possible. Found some refs to popen which seems to be php related, but nothing for c#.

Essentially, I'm looking to do the below programatically with text.txt being stuff in memory streamed to the app instead of an actual file on the hard drive.

C:\Program Files\GNU\GnuPG>type C:\test.txt | zip > plubber.zip C:\Program Files\GNU\GnuPG>type C:\test.txt | gpg -er "mycomp_operations [email protected]" > Test.pgp

Thanks for any help you may be able to give :)

Tony!

A: 

Well, named-pipes does most of what you are discussing, but to be honest it isn't worth it... in most cases, a temp file is a reasonable approach.

Marc Gravell
I agree, but was asked to look into doing this w/o having an unencrypted file on a drive at any point in the operation. It's PCI related. It's overkill, but I suppose it'll make folk ooh and ahh over our security.
A: 

You can use DotNetZip to create a zip file in-memory, but I don't know how that would interface with the gpg stuff. DotNetZip can do AES encryption, but that is obviously a different model from PGP or GPG.

Just a quick googly search turned up
this hint on GPG.

Looks like they run the gpg.exe in a separate process, sitting there waiting for input.

Cheeso
I've looked at that and have tried incorporating some of their code into an app for this, but haven't been able to get it to work.
A: 

Please review the BouncyCastle C# implementation at:

http://www.bouncycastle.org/csharp/

This will allow GPG inprocess encryption and decryption without external files. I am currently using it to do the same thing for a BizTalk pipeline component.

QSmienk
A: 

Using our SecureBlackbox components you can avoid calling external program for ZIP or PGP operations. The components operate with streams and don't need temporary files.

Eugene Mayevski 'EldoS Corp