简体   繁体   English

替代mcrypt_encrypt?

[英]Alternative to mcrypt_encrypt?

As per the php 7.0 mcrypt_decrypt is deprecated. 根据php 7.0,mcrypt_decrypt已弃用。

I have following code. 我有以下代码。

$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) );

Now we are getting 现在我们得到

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

Any alternative to fix this warning? 是否有其他解决此警告的方法?

You should use openssl_encrypt. 您应该使用openssl_encrypt。 here the link : http://php.net/manual/en/function.openssl-encrypt.php 此处的链接: http : //php.net/manual/zh/function.openssl-encrypt.php

If you want to go encryption/decryption have a look upon this blog post 如果您想进行加密/解密,请查看此博客文章
https://paragonie.com/white-paper/2015-secure-php-data-encryption it will tell you how to do it in proper way. https://paragonie.com/white-paper/2015-secure-php-data-encryption ,它将告诉您如何以正确的方式进行操作。

Alternative http://php.net/manual/en/intro.openssl.php This extension binds functions of » OpenSSL library for symmetric and asymmetric encryption and decryption. 替代方法http://php.net/manual/zh/intro.openssl.php此扩展绑定»OpenSSL库的功能,用于对称和非对称加密和解密。

Use String length 16 or 24 or 32 for variable $strKey 将字符串长度162432用作变量$strKey

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

Example : 范例:

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

Here is the details about mcrypt_encrypt() 这是有关mcrypt_encrypt()的详细信息

Alternate Solutions : 替代解决方案:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM