Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Crypt::CBC;
- use warnings;
- use strict;
- use MIME::Base64;
- my $cipher = Crypt::CBC->new( {
- 'literal_key' => 1,
- 'key' => "a" x 32,
- 'keysize'=>32,
- 'cipher'=> 'Rijndael',
- 'iv' => "\x00" x 16,
- 'padding' => 'null',
- 'prepend_iv' => 0
- });
- my $cc = 'hello world';
- my $encrypted = $cipher->encrypt($cc);
- my $decrypted = $cipher->decrypt($encrypted);
- print "encrypted : ".encode_base64($encrypted); # its: xY1F1cVS5p9/GNujSwXK2Q==
- print "decrypted : ".$decrypted;
- # trying to decrypt with php:
- <?
- $encrypted = base64_decode('xY1F1cVS5p9/GNujSwXK2Q==');
- $key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
- $iv = "";
- for($i = 0; $i < 16; $i++)
- $iv .= chr(0);
- $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_256,'','cbc','');
- mcrypt_generic_init($cipher, $key, $iv);
- $decrypted = mdecrypt_generic($cipher,$encrypted);
- mcrypt_generic_deinit($cipher);
- echo "decrypted : ".$decrypted; # should echo hello world... it doesnt.
- ?>
Advertisement
Add Comment
Please, Sign In to add comment