<small id='6Cs9q'></small><noframes id='6Cs9q'>

    <bdo id='6Cs9q'></bdo><ul id='6Cs9q'></ul>
  • <tfoot id='6Cs9q'></tfoot>
  • <i id='6Cs9q'><tr id='6Cs9q'><dt id='6Cs9q'><q id='6Cs9q'><span id='6Cs9q'><b id='6Cs9q'><form id='6Cs9q'><ins id='6Cs9q'></ins><ul id='6Cs9q'></ul><sub id='6Cs9q'></sub></form><legend id='6Cs9q'></legend><bdo id='6Cs9q'><pre id='6Cs9q'><center id='6Cs9q'></center></pre></bdo></b><th id='6Cs9q'></th></span></q></dt></tr></i><div id='6Cs9q'><tfoot id='6Cs9q'></tfoot><dl id='6Cs9q'><fieldset id='6Cs9q'></fieldset></dl></div>

  • <legend id='6Cs9q'><style id='6Cs9q'><dir id='6Cs9q'><q id='6Cs9q'></q></dir></style></legend>

      1. 准备在 PHP 7.2 中删除 Mcrypt

        Preparing for removal of Mcrypt in PHP 7.2(准备在 PHP 7.2 中删除 Mcrypt)
        • <small id='MBily'></small><noframes id='MBily'>

            <tfoot id='MBily'></tfoot>
                <tbody id='MBily'></tbody>
              <legend id='MBily'><style id='MBily'><dir id='MBily'><q id='MBily'></q></dir></style></legend>

                  <bdo id='MBily'></bdo><ul id='MBily'></ul>

                • <i id='MBily'><tr id='MBily'><dt id='MBily'><q id='MBily'><span id='MBily'><b id='MBily'><form id='MBily'><ins id='MBily'></ins><ul id='MBily'></ul><sub id='MBily'></sub></form><legend id='MBily'></legend><bdo id='MBily'><pre id='MBily'><center id='MBily'></center></pre></bdo></b><th id='MBily'></th></span></q></dt></tr></i><div id='MBily'><tfoot id='MBily'></tfoot><dl id='MBily'><fieldset id='MBily'></fieldset></dl></div>
                • 本文介绍了准备在 PHP 7.2 中删除 Mcrypt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  因此,随着时间的推移,mcrypt 将在 PHP 7.2 中出现.当然还有一个选择:openssl.

                  So as time moves on mcrypt will go in PHP 7.2. Of course there is an alternative: openssl.

                  我发现很难从 mcrypt 切换到 openssl,使用 AES 256 CBC 并保留 IV.我对密码学有点陌生,所以我并不是什么都知道,但我了解基础知识.

                  I find it difficult to switch from mcrypt to openssl, using AES 256 CBC and preserving IVs. I am sort of new to cryptography, so I don't really know everything, but I understand the basics.

                  假设我有以下代码

                  function encrypt($masterPassword, $data) 
                  {
                      $keySize = mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
                      $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
                      $iv = mcrypt_create_iv($ivSize, MCRYPT_DEV_URANDOM);
                      $key = mb_substr(hash('SHA256', $masterPassword), 0, $keySize);
                      $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_CBC, $iv);
                      return base64_encode($iv . $encrypted);
                  }
                  
                  function decrypt($masterPassword, $base64) 
                  {
                      $keySize = mcrypt_get_key_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
                      $ivSize = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
                      $key = mb_substr(hash('SHA256', $masterPassword), 0, $keySize);
                      $data = base64_decode($base64);
                      $iv = substr($data, 0, $ivSize);
                      $encrypted = substr($data, $ivSize, strlen($data));
                      $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $encrypted, MCRYPT_MODE_CBC, $iv);
                      return trim($decrypted);
                  }
                  

                  如何转换"此代码以使用由 mcrypt 插入的 openssl?

                  How can I "convert" this code to use openssl insted of mcrypt?

                  推荐答案

                  您无法转换它,因为 Rijndael-256 不是 AES-256,并且 OpenSSL 扩展不附带 Rijndael-256 支持.
                  AES-256 是具有 256 位(32 字节)密钥的 Rijndael-128.

                  You can't convert it, because Rijndael-256 is not AES-256, and the OpenSSL extension doesn't ship with Rijndael-256 support.
                  AES-256 is Rijndael-128 with a 256-bit (32-byte) key.

                  很遗憾,您必须重新加密所有数据.

                  Unfortunately, you'll have to re-encrypt all of your data.

                  此外,您当前使用的方案存在一些问题:

                  Also, the scheme you're currently using has some problems:

                  • 它缺乏身份验证(HMAC 是在 PHP 中最简单的方法)
                  • 它缺少适当的填充(mcrypt 填充零字节;您需要类似 PKCS#5 的填充),这是块模式加密安全所必需的.
                  • 它不是字节安全的(您使用的是 mb_substr())

                  好消息是 OpenSSL 会自动为你做 PKCS#5 填充,但你应该更进一步,使用像 defuse/php-encryption.

                  The good news is that OpenSSL will do PKCS#5 padding for you automatically, but you should go even further and use a solid encryption library like defuse/php-encryption.

                  这篇关于准备在 PHP 7.2 中删除 Mcrypt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                  <i id='6YmnB'><tr id='6YmnB'><dt id='6YmnB'><q id='6YmnB'><span id='6YmnB'><b id='6YmnB'><form id='6YmnB'><ins id='6YmnB'></ins><ul id='6YmnB'></ul><sub id='6YmnB'></sub></form><legend id='6YmnB'></legend><bdo id='6YmnB'><pre id='6YmnB'><center id='6YmnB'></center></pre></bdo></b><th id='6YmnB'></th></span></q></dt></tr></i><div id='6YmnB'><tfoot id='6YmnB'></tfoot><dl id='6YmnB'><fieldset id='6YmnB'></fieldset></dl></div>
                • <legend id='6YmnB'><style id='6YmnB'><dir id='6YmnB'><q id='6YmnB'></q></dir></style></legend>
                  • <bdo id='6YmnB'></bdo><ul id='6YmnB'></ul>

                    1. <tfoot id='6YmnB'></tfoot>

                      <small id='6YmnB'></small><noframes id='6YmnB'>

                              <tbody id='6YmnB'></tbody>