How do I decrypt AES-generated crypttext in PHP with Perl? -
i have following code in php:
$key="ed8677a0fc735e9bf1d7bca3310bb82854b5217589f2e00dd3bab399be9707a7"; $file="test"; $in = fopen($file, 'rb'); $out = fopen($file.'.encrypted', 'wb'); $file_size = filesize($file); echo "[?] filesize: ".$file_size."\n"; echo "\n[?] key: $key \n"; $block_size = mcrypt_get_block_size(mcrypt_rijndael_128, mcrypt_mode_cbc); // encrypt echo date('y-m-d h:i:s')."\n"; $time_s = time(); echo "[1] encrypting.... \n"; $content=''; $encrypt=true; $ip=0; while (!feof($in)) { $off_s = ftell($in); $content = fread($in, 8192); $off_e = ftell($in); $size = $off_e-$off_s; //if (($size!=8192)&&($size>0)) if ($size>0) { if ($size!=8192) $content = pkcs5_pad($content, $size, $block_size); $encrypted = mcrypt_cbc(mcrypt_rijndael_128, substr($key,0,32) ,$content, mcrypt_encrypt, substr($key,32,16)); fwrite($out, $encrypted); } } fclose($in); fclose($out);
how decrypt in perl? tried no success:
use archive::zip qw( :error_codes :constants ); use posix; use file::basename; use crypt::cbc; use digest::md5 qw(md5 md5_hex); # a) decrypt $key="ed8677a0fc735e9bf1d7bca3310bb82854b5217589f2e00dd3bab399be9707a7"; $sourcefile="test.encrypted"; $cipher = crypt::cbc->new( {'key' => substr($key,0,32), 'cipher'=> 'rijndael', 'blocksize' => 16, 'iv' => substr($key,32,16), 'regenerate_key' => 0, 'padding' => 'standard', 'prepend_iv' => 0, 'header' => 'none', }); open (inf1, "< ".$sourcefile) || die; open (outf1, "> ".$sourcefile.".decrypt") || die; while (my $size = read(inf1,my $buf, 8192 ) ) { $count += $size; $buf2 = $cipher->decrypt($buf); $buf2 .= $cipher->finish(); print outf1 $buf2; #syswrite (outf1, $buf2, $size); } close(inf1); close(outf1);
i think there problem padding - way php , perl it, can't find proper solution.
Comments
Post a Comment