php升级后,openssl解密功能无法正常工作



我有一个使用openssl_encryptopenssl_decrypt的PHP应用程序,它在过去四年中一直运行良好
最近,应用程序在调用openssl_decrypt函数时显示false

这是加密部分:

<?php
$password = "iR0nM@N2017!?KOreVoNick";
$method = "aes128";
$iv = "69kjg23423L@cEv7";
$montant = htmlentities($_POST['montant'])-$mutation;
$numeroCheque = openssl_encrypt(htmlentities($_POST['numeroCheque']), $method, $password, 0, $iv);
$designationSociete = openssl_encrypt(htmlentities($_POST['designationSociete']), $method, $password, 0, $iv);
$designationPersonne = openssl_encrypt(htmlentities($_POST['designationPersonne']), $method, $password, 0, $iv);
$dateCheque = htmlentities($_POST['dateCheque']);
$idProjet = htmlentities($_POST['idProjet']);
$createdBy = $login;
$created = date('d/m/Y h:m');
$statut = htmlentities($_POST['statut']);
$compteBancaire = openssl_encrypt(htmlentities($_POST['compteBancaire']), $method, $password, 0, $iv);
$url = "";
$cheque = new Cheque(array('numero' => $numeroCheque , 'montant' => $montant,
'designationSociete' => $designationSociete, 'designationPersonne' => $designationPersonne, 
'dateCheque' => $dateCheque, 'idProjet' =>$idProjet, 'idSociete' => $idSociete, 'compteBancaire' => $compteBancaire, 'createdBy' => $createdBy, 'created' => $created,
'statut' => $statut, 'url' => $url));
$chequeManager = new ChequeManager($pdo);
$chequeManager->add($cheque);

对于解密来说,它很容易:

openssl_decrypt($cheque->numero(), $method, $password, 0, $iv);

这是我使用openssl_error_string()时出现的错误

'error:0607A082:digital envelope routines:EVP_CIPHER_CTX_set_key_length:invalid key length'

有什么建议吗?

我尝试过以下操作:

<?php
$cleartext = "The quick brown fox jumps over the lazy dog";
$password = "iR0nM@N2017!?KOreVoNick";
$method = "aes128";
$iv = "69kjg23423L@cEv7";
$enctext = openssl_encrypt($cleartext, $method, $password, 0, $iv);
$dectext = openssl_decrypt($enctext, $method, $password, 0, $iv);
header("content-type:text/plain");
echo "decrypted: $dectextnn";
echo "encrypted: $enctextnn";
echo "orig: $cleartextn";

结果

decrypted: The quick brown fox jumps over the lazy dog
encrypted: fyYcGEVOpH9cEZuBIN4S1GRDp/kU+Kzv1UJUp2UBGpPv/R+BxxbBDArKa+ugvOOr
orig: The quick brown fox jumps over the lazy dog

因此,我的结论是,你对解密内容的长度或填充有一些问题。

PHP版本:

Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.4.3

最新更新