【问题标题】:Alternative to mcrypt_encrypt?替代 mcrypt_encrypt?
【发布时间】:2017-06-08 06:05:33
【问题描述】:

根据 php 7.0,不推荐使用 mcrypt_decrypt。

我有以下代码。

$intSize= mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB );
$strSize = mcrypt_create_iv( $intSize, MCRYPT_RAND );
$strText = ( true == $boolTrimText ) ? trim( $strText ) : $strText;
$strResult = base64_encode( mcrypt_encrypt( MCRYPT_RIJNDAEL_256, ( string ) $strKey, ( string ) $strText, MCRYPT_MODE_ECB, $strSize) );

现在我们得到了

mcrypt_encrypt(): Key of size 0 not supported by this algorithm. Only keys of sizes 16, 24 or 32 supported

有什么办法可以解决这个警告吗?

【问题讨论】:

    标签: php


    【解决方案1】:

    您应该使用 openssl_encrypt。这里是链接:http://php.net/manual/en/function.openssl-encrypt.php

    【讨论】:

      【解决方案2】:

      如果您想进行加密/解密,请查看这篇博文
      https://paragonie.com/white-paper/2015-secure-php-data-encryption,它将告诉您如何以正确的方式进行操作。

      替代http://php.net/manual/en/intro.openssl.php 此扩展绑定了 » OpenSSL 库的功能,用于对称和非对称加解密。

      【讨论】:

        【解决方案3】:

        对变量$strKey使用字符串长度162432

        $strKey = 'YOUR_STRING'; #This string length should be 16 or 24 or 32
        

        示例:

        $strKey = '1234567890abcdef';                 #Length 16
        $strKey = '1234567890abcdef76hgfrdg';         #Length 24
        $strKey = '1234567890abcdef1234567890abcdef'; #Length 32
        

        这里是mcrypt_encrypt()的详细信息

        替代解决方案:

        【讨论】:

          猜你喜欢
          • 2012-03-20
          • 2019-07-20
          • 1970-01-01
          • 2018-09-10
          • 2016-11-16
          • 2016-09-12
          • 2011-02-15
          • 2018-02-05
          • 2011-12-28
          相关资源
          最近更新 更多