php - url中的加密/解密字符串随机停止工作
问题描述
我具有加密和解密从电子邮件的 url 中传递的字符串的功能。此功能已经运行良好一年,最近停止工作。几周内没有部署到生产服务器。没有代码更改......我能想到的服务器没有任何更改。我很难理解为什么这会停止工作。
当我向用户发送估计值时,我对字符串进行了加密
$token = $contact->email."|".$user->id."|".$estimate->magiclink;
$cipher_method = 'aes-128-ctr';
$enc_key = openssl_digest(php_uname(), 'SHA256', TRUE);
$enc_iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($cipher_method));
$crypted_token = openssl_encrypt($token, $cipher_method, $enc_key, 0, $enc_iv) . "::" . bin2hex($enc_iv);
do{
$cipher_method = 'aes-128-ctr';
$enc_key = openssl_digest(php_uname(), 'SHA256', TRUE);
$enc_iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length($cipher_method));
$crypted_token = openssl_encrypt($token, $cipher_method, $enc_key, 0, $enc_iv) . "::" . bin2hex($enc_iv);
}
while(is_int(strpos($crypted_token, '/'))); //if there's an int it means a / was found
unset($token, $cipher_method, $enc_key, $enc_iv);
$linkToEstimate = '/viewestimateeasy/'.$crypted_token;
当用户单击电子邮件中的链接时,我会解密该字符串。 该字符串包含他们的用户 ID、电子邮件地址和唯一标识符
list($crypted_token, $enc_iv) = explode("::", $crypted_token);
$cipher_method = 'aes-128-ctr';
$enc_key = openssl_digest(php_uname(), 'SHA256', TRUE);
$token = openssl_decrypt($crypted_token, $cipher_method, $enc_key, 0, hex2bin($enc_iv));
unset($crypted_token, $cipher_method, $enc_key, $enc_iv);
//get the token parts
list($email, $user_id, $magiclink) = explode("|", $token);
我希望 $token 的值看起来像“user@domain.com|423|340934fafasdf9cas532424”。
我得到一个似乎没有正确编码的值。我得到的是这样的:“И�^�I�+y��(�Ƀa��lqj��>O������UDmE�Ĩ���l�")�]” 0��Q"
我的代码
list($email, $user_id, $magiclink) = explode("|", $token);
正在返回错误“未定义的数组键 1”,因为 $token 不包含任何要拆分的管道。
正如我所提到的,这只是随机停止工作。没有对生产环境进行部署。就好像我的代码之外的东西已经改变了。
我用一个旧链接进行了测试,我确信过去可以工作,但我遇到了同样的错误。
有没有人有什么建议?
解决方案
推荐阅读
- python - 在 python3.7 中安装 pytorch 的问题
- android - 打开失败:EACCES(权限被拒绝)ANDROID 11
- c++ - clang/clang-cl 未定义符号“__tls_index”(自定义 CRT 实现)
- winapi - WIN32:所有者绘制按钮中的重复标准按钮控件(禁用图标/热键下划线)?
- ios - Ios Webrtc,系统弹出窗口在视频流中不可见
- php - 在 href 按钮中存储变量
- nginx - 手动启动nginx,静态html没问题,但是用systemctl启动nginx,是403
- c# - 找不到类型或命名空间名称“ILogger<>”(您是否缺少 using 指令或程序集引用?) [PaymentApi]
- save - RapidMiner:如何导出流程的整个结果集合?
- c++ - 无法使用 alsa 在 linux 中播放 wav 文件