Created
November 27, 2013 10:51
-
-
Save debility-zz/7673835 to your computer and use it in GitHub Desktop.
rijndael-256 decode (PL/Perl)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION rd256_decode(text, text, text) | |
RETURNS text AS | |
$BODY$ | |
use Mcrypt; | |
use MIME::Base64; | |
use utf8; | |
use Encode qw(encode decode); | |
my ($encoded, $key, $iv) = @_; | |
my $td = Mcrypt->new( | |
algorithm => Mcrypt::RIJNDAEL_256(), | |
mode => Mcrypt::CBC(), | |
verbose => 0, | |
); | |
$td->init( $key, $iv ); | |
my $data = decode_base64($encoded); | |
my $dec_padded = decode('UTF-8', $td->decrypt( $data )); | |
my $decoded = _trim_pad( $dec_padded ); | |
$decoded =~ s/\0//g; | |
return $decoded; | |
sub _trim_pad { | |
my $str = shift || ''; | |
my $pad_char = " "; | |
$str =~ s/${pad_char}+$//; | |
return $str; | |
} | |
$BODY$ | |
LANGUAGE plperlu IMMUTABLE STRICT | |
COST 100; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment