hawtin has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks: Every so often I come across a difficulty that I think is so common someone else must have a solution, but when I look I cannot find it. Here is one that I am struggling with at the moment.
I have a Perl application that stores sensitive data in an XML file. Which was perfect during development because it made it easy to see what was happening and try out various situations by editing the file. Now that I am moving toward deployment I want to provide "compress" and "encrypt" capabilities to the application user, something like this:
+---+
-->-Compress->-- -->-Encrypt->-| F |
+-----+ / \ / | i |
| App |->--? ->--? | l |
+-----+ \ / \ | e |
-->---->----->-- -->---->---->-| s |
+---+
Which I thought I could implement like this (error handling removed for clarity):
... use MyData; $f = new MyData(file => "foo.compressed",encrypt_key =>""); ... package MyData; sub new { ... my $parser = XML::SAX::ParserFactory->parser( Handler => MyData::Handler->new); my $fh = _file_open($filename,$key); $parser->parse_file($fh); ... } sub _file_open { my($file_name,$encrypt_key) = @_; $encrypt_key = "" if(!defined $encrypt_key); # This first bit works OK my $compress = ""; my $compress = 1 if($file_name =~ /\.compressed$/); if($encrypt_key eq "") { return new IO::Zlib($file_name,"rb") if($compress); return new IO::File($file_name,"r"); } # This is where I get into trouble ????? }
Now if I was running on a *IX machine I could create an encryption process and pipe my (possibly) compressed data to it, but I'm on Windows and I can't get pipe and fork to do anything useful. The files are small enough that I could read them into memory, decrypt them, inflate them and then create an IO::Scalar for SAX, but that would need me to know more about the Compress::Zlib than I currently do.
I am running the ActiveState 5.6.1 on a Windows 2000 machine
This must be a common requirement and I am sure that the only reason the answer is not obvious is my lack of encryption experience. How have others done this?
Update: Of course I also want to do something similar when writing a file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compressing and Encrypting files on Windows
by tachyon (Chancellor) on Nov 01, 2004 at 14:03 UTC | |
by jon_barber (Initiate) on Nov 02, 2004 at 11:23 UTC | |
by tachyon (Chancellor) on Nov 02, 2004 at 22:34 UTC | |
by jon_barber (Initiate) on Nov 03, 2004 at 04:56 UTC | |
by tachyon (Chancellor) on Nov 03, 2004 at 06:12 UTC | |
| |
|
Re: Compressing and Encrypting files on Windows
by elwarren (Priest) on Nov 01, 2004 at 17:21 UTC | |
by hawtin (Prior) on Nov 02, 2004 at 08:46 UTC | |
by elwarren (Priest) on Nov 02, 2004 at 17:29 UTC | |
by hawtin (Prior) on Nov 03, 2004 at 09:07 UTC | |
by elwarren (Priest) on Nov 03, 2004 at 17:02 UTC | |
|
Re: Compressing and Encrypting files on Windows
by Anonymous Monk on Nov 01, 2004 at 09:54 UTC | |
|
My Solution
by hawtin (Prior) on Nov 02, 2004 at 08:36 UTC | |
|
Re: Compressing and Encrypting files on Windows
by chanio (Priest) on Nov 02, 2004 at 00:32 UTC | |
| A reply falls below the community's threshold of quality. You may see it by logging in. |