AES加密在php和解密在perl



我的perl脚本不是在php中解密AES加密字符串

我想我这里缺少一些东西,是否有任何示例脚本可以使用IV在perl中解密

这是 php 中的加密脚本

<?php
$encryption_key = base64_decode('OhjsqEflVL1GNteBIgpD1ngMvS3vVicAkfTyerJjr/c=');
$iv = "1234567812345678";
$data = "PLAIN TEXT";
$encrypted = openssl_encrypt($data, 'aes-256-cbc', $encryption_key, OPENSSL_RAW_DATA, $iv);
print "Encrypted string = <".base64_encode($encrypted).">n";
$decrypted = openssl_decrypt($encrypted,'aes-256-cbc', $encryption_key, OPENSSL_RAW_DATA , $iv);
print "DECRYPTED DATA=<$decrypted>n";
?>

这是 perl 中的解密脚本

use Crypt::CBC;
use Crypt::Cipher::AES;
use MIME::Base64 qw(decode_base64);
use strict;
my $key=decode_base64('OhjsqEflVL1GNteBIgpD1ngMvS3vVicAkfTyerJjr/c=')
my $iv = "1234567812345678";
$iv=undef;
my $cbc = Crypt::CBC->new( -cipher=>'Cipher::AES', -key=>$key, -iv=>$iv );
my $plaintext = $cbc->decrypt(decode_base64('sR9aVLpjHgpbM7Kw8hb7Ig=='));
print "$plaintextn";

你的代码来自 http://search.cpan.org/dist/CryptX/lib/Crypt/Cipher/AES.pm

但是有一个错误。它给了我

cannot use salt-based IV generation if literal IV is specified

CBC 模块给出了一个有效的代码。

我看到您添加了从 Crypt CBC 模块文档中获取的选项,它对我来说也很好用。

最新更新