我试图使用chilkat
功能测试文件加密。基于对this例如页面发现的代码,我替换为最后一部分:奇尔卡特加密不能按预期工作
# Encrypt a string...
# The input string is 44 ANSI characters (i.e. 44 bytes), so
# the output should be 48 bytes (a multiple of 16).
# Because the output is a hex string, it should
# be 96 characters long (2 chars per byte).
my $input = "sample.pdf";
# create file handle for the pdf file
open my $fh, '<', $input or die $!;
binmode ($fh);
# the output should be sample.pdf.enc.dec
open my $ffh, '>', "$input.enc.dec" or die $!;
binmode $ffh;
my $encStr;
# read 16 bytes at a time
while (read($fh,my $block,16)) {
# encrypt the 16 bytes block using encryptStringEnc sub provided by chilkat
$encStr = $crypt->encryptStringENC($block);
# Now decrypt:
# decrypt the encrypted block
my $decStr = $crypt->decryptStringENC($encStr);
# print it in the sample.pdf.enc.dec file
print $ffh $decStr;
}
close $fh;
close $ffh;
免责声明: 我知道,不建议文件加密CBC模式,因为如果一个块丢失,其他块丢失太。 输出文件已损坏,当我在两个文件中进行超越比较时,出现了匹配的文件块,并且没有文件块。我究竟做错了什么?
如果不知道'$ crypt'是什么类型的对象,我们就无法得到任何帮助。它是如何创建的? –
@DaveCross快速搜索显示它是 - * fck这个,让我们在一个类中完成 - * [CkCrypt2](https://www.chilkatsoft.com/refdoc/vcCkCrypt2Doc.html)组件。 –
@MaartenBodewes:我想你的意思是链接到[Perl模块](https://www.chilkatsoft.com/refdoc/perlCkCrypt2Ref.html)而不是C++。但我的观点是,我们不应该需要做这种搜索。 –