This is
the week for Excel questions, isn't it?
At any rate, to do this you will need OpenSSL for Win32 (the binaries). Note: You can use whatever encryption tools you want. This example uses OpenSSL.
You will need to learn how to encrypt something with it unless you already know how or are doing it some other way.
I used:
C:\Temp\openSSL\bin>openssl enc -aes-256-cbc -a -salt -in foo.txt -out
+ file.enc
enter aes-256-cbc encryption password:
Verifying - enter aes-256-cbc encryption password:
*****
And got an encrypted file:
C:\Temp\openSSL\bin>type file.enc
U2FsdGVkX19MZ5n8Rb41XIrAuhwtlBUPPWhbvSe4b0J3Wfj8QRRwqCxuqTG69Ta9
If you read the tutorial it will show you how to decrypt the file, provided the system decrypting has both the same cipher and the password (which I assume you will share your recipient via some more secure means, like the telephone).
Now, your only 'problem' is convincing Excel to spit out a text file with the data:
use Win32::OLE;
my ($filename) = "F:\\Incidents.xls";
my ($nextStep) = q|mysystem.cgi?f=incidents_show|;
my ($csv) = ".\\data\\_csv\\incidents.csv";
if(-f $filename)
{
my(@fnStat) = stat($filename);
my(@csvStat)= stat($csv);
if($fnStat[9] > $csvStat[9]) {
my($obj) = Win32::OLE->new("Excel.Application");
$obj->Workbooks->Open (q|F:\Incidents.xls|);
if (-f q|c:\data\_csv\incidents.csv|) {unlink(q|c:\data\_csv\i
+ncidents.csv|) or die "Cannot unlink the incidents.csv file!"};
$obj->ActiveWorkbook->SaveAs(q|C:\data\_csv\incidents.csv|, 6)
+;
$obj->ActiveWorkbook->Close(0);
$obj->Quit();
"The Incident.xls file has been recently modified and the exc
+el file has been created! <a href=\"$nextStep\">Click</a>";
}
else
{
"File is okay. Proceed to CSV. <a href=\"$nextStep\">Click</a
+>";
}
}
else
{ "Could not find Incidents.xls!"};
The above code checks to see whether the file on the local disk is older than the spreadsheet's last modification time. If so, it initiates the download.
Now you can shell out to OpenSSL to encrypt that file. A possible vulnerability with this method -- having a Perl script encrypt a separate file -- is that you will have to maintain the password inside of your perl script somewhere. Perhaps there is an encryption method where you wouldn't need a shared password, like PGP? I'm not sure. Try Google.
Update: Here is some more on passwords with OpenSSL
Celebrate Intellectual Diversity
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.