Guest User

Untitled

a guest
Jan 10th, 2012
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. use Crypt::CBC;
  2. use warnings;
  3. use strict;
  4. use MIME::Base64;
  5.  
  6. my $cipher = Crypt::CBC->new( {
  7. 'literal_key' => 1,
  8. 'key' => "a" x 32,
  9. 'keysize'=>32,
  10. 'cipher'=> 'Rijndael',
  11. 'iv' => "\x00" x 16,
  12. 'padding' => 'null',
  13. 'prepend_iv' => 0
  14. });
  15. my $cc = 'hello world';
  16. my $encrypted = $cipher->encrypt($cc);
  17. my $decrypted = $cipher->decrypt($encrypted);
  18.  
  19. print "encrypted : ".encode_base64($encrypted); # its: xY1F1cVS5p9/GNujSwXK2Q==
  20. print "decrypted : ".$decrypted;
  21.  
  22. # trying to decrypt with php:
  23. <?
  24. $encrypted = base64_decode('xY1F1cVS5p9/GNujSwXK2Q==');
  25. $key = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa';
  26. $iv = "";
  27. for($i = 0; $i < 16; $i++)
  28. $iv .= chr(0);
  29.  
  30. $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_256,'','cbc','');
  31.  
  32. mcrypt_generic_init($cipher, $key, $iv);
  33.  
  34.  
  35. $decrypted = mdecrypt_generic($cipher,$encrypted);
  36. mcrypt_generic_deinit($cipher);
  37.  
  38. echo "decrypted : ".$decrypted; # should echo hello world... it doesnt.
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment