【发布时间】:2021-03-29 10:52:29
【问题描述】:
我有一个使用openssl_encrypt 和openssl_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'
有什么建议吗?
【问题讨论】:
-
$cheque->numero()的内容是什么? -
$cheque->numero() 它是一个字符串
-
看看这个过程的另一半可能会有用,你能显示你的加密代码吗
-
我猜你的问题中的关键与你程序中的关键不一样,这是明智的。在完全相同的长度上尝试一下,看看是否仍然出现错误...
-
如果您向我们展示的代码确实有效,它会有所帮助。 Minimal, Complete and Verifiable Example