Perl - Cryptography
Packing strings correctly is part of the fun with using use Crypt::Rijndael. Fortunately here is a simple example of how to do it.
#!/usr/bin/perl use Crypt::Rijndael; $keyStr = SomethingSecret $cipher = new Crypt::Rijndael($keyStr, Crypt::Rijndael::MODE_CBC()); $dataToSecure = 'Hello World'; $cipheredText = $cipher->encrypt( "\0" x (256 - length($dataToSecure) % 256 ) . $dataToSecure); # cipheredText now has the secured data. To decrypt it: $decryptedData = $cipher->decrypt($cipheredText);
Form Processing
Form data is usually encoded but this little snippet makes it easy to extract the data. I found this at http://wiki.linuxquestions.org/wiki/Perl
foreach (split/&/, $ENV{'QUERY_STRING') { tr/+/ /; ($name,$value) = split /=/, $_; $name =~ s/%(..)/pack('c', hex($1))/eg; $value =~ s/%(..)/pack('c', hex($1))/eg; $parameters{$name} = $value; push @get_names,$name; }; foreach (split /&/, (read STDIN,$input_buffer,$ENV{"CONTENT_LENGTH"})) { tr/+/ /; ($name,$value) = split (/=/, $_); $name =~ s/%(..)/pack('c', hex($1))/eg; $value =~ s/%(..)/pack('c', hex($1))/eg; push @post_names,$name; $parameters{$name} = $value; };
Copyright © 2009. BrianArita.Com.