我试图在 Perl 中加密然后解密二进制文件但没有成功,解密的文件总是与原始文件不同。我尝试了 Blowfish 和 AES (Rijandael),这是一个简短的示例:
#!/usr/bin/perl
use Crypt::CBC;
use autodie;
my $cipher = Crypt::CBC->new(
-key => 'my secret key',
-cipher => 'Blowfish',
-header => 'none',
-iv => 'dupajasi'
);
$cipher->start('encrypting');
my $sourcefile = "fs9419105v001s.zip";
{
open(my $OUTF, '>', "$sourcefile.perl.crypt");
open(my $F, '<', $sourcefile);
print "[?] Encrypting ... \n";
while (read($F, $buffer, 1024)) {
print $OUTF $cipher->crypt($buffer);
}
print {$OUTF} $cipher->finish;
close($OUTF);
}
print "[?] Decrypting.,..... \n";
$cipher2 = Crypt::CBC->new(
-key => 'my secret key',
-cipher => 'Blowfish',
-header => 'none',
-iv => 'dupajasi'
);
{
open(my $OUTF, '>', "$sourcefile.perl.decrypt");
open(my $F, '<', "$sourcefile.perl.crypt");
while (read($F, $buffer, 1024)) {
print {$OUTF} $cipher2->decrypt($buffer);
}
print {$OUTF} $cipher2->finish;
close($OUTF);
}
有人可以帮我找出问题所在吗?