[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Omaha.pm] Crypt::Tea
Holy crap!
I love Perl, CPAN, and now I also love Peter Billam. -grin-
We painted ourselves into a corner on a huge project with a tiny flaw.
I thought to myself -- what I really need is some tiny Perl gizmo that
would allow me to encrypt an integer, let me hand that off to the web
client's browser (into a cookie), and be able to decrypt it when it
comes back to the web server. (So they can't jack w/ the integer in
their browser.) I had never used such a thing before.
5 minutes on CPAN and I stumbled into Crypt::Tea.
http://search.cpan.org/~pjb/Crypt-Tea-2.04/Tea.pm
My demo program:
----------------
#!/usr/bin/perl
use Crypt::Tea;
$key = '18*71^asdj 1$$![&.={[ 0182312m';
my $secret = "My secret! shhh!";
for (1..20) {
push @secrets, encrypt($secret, $key);
}
foreach (@secrets) {
print "$_ -> ";
print decrypt($_, $key);
print "\n";
}
Output:
--------------
# ./j.pl
mgb7NpXEhmY_DcnWFs6_thmm8dEmW2zz -> My secret! shhh!
QCOd3vpp6QZjD__c25nJtVlQ_sfT-rMm -> My secret! shhh!
eapzrEU30v1y8Lqo53QW6R51y2QVvA2J -> My secret! shhh!
WKgMDakGJjofJCPcSmsFTKHLvlsllokc -> My secret! shhh!
0f7NbSdS2yxeZGgLEheeN6tiYYfy-kQy -> My secret! shhh!
ECsGzMPflc6WYpZ8RZuiaRE6kyTVMo3Q -> My secret! shhh!
0f7NbSdS2yxeZGgLEheeN5qe-qzfKRjK -> My secret! shhh!
-fpqAgj0cvGtT5pj6NArX1h_62f_eB4T -> My secret! shhh!
eQaegpDVD6Euz-sCJpJN654pl1ZVNpRZ -> My secret! shhh!
rhLplwrT6RYXq-9ihEsWJ3YjH5Wwjb4I -> My secret! shhh!
tW-BhTOg0Z7PxxVZ0mYcBBKb0wayuDik -> My secret! shhh!
jaNmWK5Wm8kYOHBgu7zvLkKc9wMYsH9G -> My secret! shhh!
QW1IuWlaOZ-knID8K3OYmDVqsWiIeMKH -> My secret! shhh!
d0H4kiTESeQzceTQ-AHrD3pXUNhCQucw -> My secret! shhh!
rhLplwrT6RYXq-9ihEsWJ8YUet7WcQAz -> My secret! shhh!
QCOd3vpp6QZjD__c25nJtYTRHuO4pmzY -> My secret! shhh!
-1yP8-h9KABP5MBRp7z08euklmL82YUq -> My secret! shhh!
0f7NbSdS2yxeZGgLEheeN0XMOmcdgmbP -> My secret! shhh!
GQj85LnrKurqMeqOJ3aUA8btA2aLPpYX -> My secret! shhh!
VaM4A7NzxkxCyeJi7F1F3bnsWtq7FMuX -> My secret! shhh!
Elapsed time: 30 minutes, including this email.
Awesome. I love Perl + CPAN.
Thanks Peter!
j
Omaha Perl Mongers: http://omaha.pm.org