如何使用解密的AES密钥和执行php脚本与它的结果


How to use decrypted AES key and execute php script with it's result

我目前有一个PHP脚本解密存储在mysql中的密码,然后连接到imap,到目前为止,解密工作很好,我甚至可以回声结果,它确实返回正确的密码,但由于某种原因imap没有连接。

这是我的

$email_pass = $sql['EMAIL_PASS'];
//Decrypt Account password.
function encrypt_decrypt($action, $string) {
$output = false;
$encrypt_method = "AES-256-CBC";
$secret_key = 'ksdkjdksdk';
$secret_iv = 'sdfdfdfdf';
// hash
$key = hash('sha256', $secret_key);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16);
if( $action == 'decrypt' ){
    $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
}
return $output;
}
$dec_pass = encrypt_decrypt('decrypt', $email_pass);
echo $dec_pass; // this echo the correct password.

//connect to imap
$i = @imap_open("{{$server}:$port/$con_type}$eml_from", $account_uname, $dec_pass);

Imap连接失败。如果我手动输入密码,它就能工作。有什么建议吗?

我得到了这个工作,结果证明代码很好,邮箱帐户被锁定在服务器上,因为我在测试时失败了太多的尝试。:) . .