簡體   English   中英

替代mcrypt_encrypt?

[英]Alternative to mcrypt_encrypt?

根據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

是否有其他解決此警告的方法?

您應該使用openssl_encrypt。 此處的鏈接: http : //php.net/manual/zh/function.openssl-encrypt.php

如果您想進行加密/解密,請查看此博客文章
https://paragonie.com/white-paper/2015-secure-php-data-encryption ,它將告訴您如何以正確的方式進行操作。

替代方法http://php.net/manual/zh/intro.openssl.php此擴展綁定»OpenSSL庫的功能,用於對稱和非對稱加密和解密。

將字符串長度162432用作變量$strKey

$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()的詳細信息

替代解決方案:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM