douyingbei1458 2019-03-07 07:34
浏览 212

解密php 7.2中的数据,使用AES在php 5.6中加密

I used a following method to Encrypt and Decrypt data between a php application and android app, It was working fine in php 5.6, After upgrading to php 7.2 it stopped working, Now I have moved back to php 5.6 temporarily. I know php mcrypt is depreciated. Now my problem is I cannot give update to Android App, I have to fix this somehow in the server side, I have predefined key and iv , Both in server side as well as app, What do I do so that I can use same key and iv and encrypt and decrypt data on sever side in php 7.2. Thanks in advance

 class MCrypt
        {
                private $key = 'Some Key'; 
                private $iv = 'Some IV'; 


                function __construct()
                {
                }

                function encrypt($str) {

                  //$key = $this->hex2bin($key);    
                  $iv = $this->iv;

                  $td = mcrypt_module_open('rijndael-128', '', 'cbc', $iv);

                  mcrypt_generic_init($td, $this->key, $iv);
                  $encrypted = mcrypt_generic($td, $str);

                  mcrypt_generic_deinit($td);
                  mcrypt_module_close($td);

                  return bin2hex($encrypted);
                }

                function decrypt($code) {
                  //$key = $this->hex2bin($key);
                  $code = $this->hex2bin($code);
                  $iv = $this->iv;

                  $td = mcrypt_module_open('rijndael-128', '', 'cbc', $iv);

                  mcrypt_generic_init($td, $this->key, $iv);
                  $decrypted = mdecrypt_generic($td, $code);

                  mcrypt_generic_deinit($td);
                  mcrypt_module_close($td);

                  return utf8_encode(trim($decrypted));
                }

                protected function hex2bin($hexdata) {
                  $bindata = '';

                  for ($i = 0; $i < strlen($hexdata); $i += 2) {
                        $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
                  }

                  return $bindata;
                }

        }
  • 写回答

1条回答 默认 最新

  • dtjo87679 2019-03-07 07:54
    关注

    mcrypt is deprecated in 7.2 and is not included by default. However, you can still install mcrypt manually if you'd like. You could also use openssl_encrypt() and openssl_decrypt() instead.

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大