Error[8]: Undefined offset: 8, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

PHP7 openssl函数替换mcrypt函数加密解密方法

PHP7 openssl函数替换mcrypt函数加密解密

以下是两者的区别及openssl替换mcrypt的方法:

替代

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789"; //要加密的数据

if(PHP_VERSION<5.6){
    $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    echo 'mcrypt_encrypt:'.$a.'<br>';
    //rtrim 移除字符串右侧的空白字符
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'运行结果');
    echo 'mcrypt_decrypt:'.$decrypt.'<br>';
} //使用mcrypt函数来对比



$len = strlen($data);
if($len%8){
    $data = str_pad($data,$len+8-$len%8,"
mcrypt_encrypt:O4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt:123456789
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt:123456789
"); }//使用空字符填充字符串的右侧,使字符串位数变为8的倍数 $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt:'.$decrypt.'<br>';

然后来个对比,看看这两个函数的速度:

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789";

if(PHP_VERSION<5.6){
    $start = microtime(true);
    for($i=0;$i<10000;$i++){
        $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    }
    echo 'mcrypt_time:'; echo microtime(true)-$start.'<br>';
    echo 'mcrypt_encrypt'.$a.'<br>';
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'
mcrypt_time:1.8425710201263
mcrypt_encryptO4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt123456789
openssl_time:0.023201942443848
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt123456789
'); echo 'mcrypt_decrypt'.$decrypt.'<br>'; } $start = microtime(true); for($i=0;$i<10000;$i++){ $len = strlen($data); if($len%8){ $data = str_pad($data,$len+8-$len%8,"[+++]"); } $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); } echo "openssl_time:"; echo microtime(true)-$start . '<br>'; echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt'.$decrypt.'<br>';

[+++]

[+++]

结果

[+++]

本文来自php7教程栏目,欢迎学习。

以上就是PHP7 openssl函数替换mcrypt函数加密解密方法的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

Error[8]: Undefined offset: 9, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

PHP7 openssl函数替换mcrypt函数加密解密方法

PHP7 openssl函数替换mcrypt函数加密解密

以下是两者的区别及openssl替换mcrypt的方法:

替代

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789"; //要加密的数据

if(PHP_VERSION<5.6){
    $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    echo 'mcrypt_encrypt:'.$a.'<br>';
    //rtrim 移除字符串右侧的空白字符
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'运行结果');
    echo 'mcrypt_decrypt:'.$decrypt.'<br>';
} //使用mcrypt函数来对比



$len = strlen($data);
if($len%8){
    $data = str_pad($data,$len+8-$len%8,"
mcrypt_encrypt:O4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt:123456789
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt:123456789
"); }//使用空字符填充字符串的右侧,使字符串位数变为8的倍数 $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt:'.$decrypt.'<br>';

然后来个对比,看看这两个函数的速度:

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789";

if(PHP_VERSION<5.6){
    $start = microtime(true);
    for($i=0;$i<10000;$i++){
        $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    }
    echo 'mcrypt_time:'; echo microtime(true)-$start.'<br>';
    echo 'mcrypt_encrypt'.$a.'<br>';
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'
mcrypt_time:1.8425710201263
mcrypt_encryptO4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt123456789
openssl_time:0.023201942443848
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt123456789
'); echo 'mcrypt_decrypt'.$decrypt.'<br>'; } $start = microtime(true); for($i=0;$i<10000;$i++){ $len = strlen($data); if($len%8){ $data = str_pad($data,$len+8-$len%8,""); } $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); } echo "openssl_time:"; echo microtime(true)-$start . '<br>'; echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt'.$decrypt.'<br>';

[+++]

[+++]

结果

[+++]

本文来自php7教程栏目,欢迎学习。

以上就是PHP7 openssl函数替换mcrypt函数加密解密方法的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

Error[8]: Undefined offset: 10, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

PHP7 openssl函数替换mcrypt函数加密解密方法

PHP7 openssl函数替换mcrypt函数加密解密

以下是两者的区别及openssl替换mcrypt的方法:

替代

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789"; //要加密的数据

if(PHP_VERSION<5.6){
    $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    echo 'mcrypt_encrypt:'.$a.'<br>';
    //rtrim 移除字符串右侧的空白字符
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'运行结果');
    echo 'mcrypt_decrypt:'.$decrypt.'<br>';
} //使用mcrypt函数来对比



$len = strlen($data);
if($len%8){
    $data = str_pad($data,$len+8-$len%8,"
mcrypt_encrypt:O4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt:123456789
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt:123456789
"); }//使用空字符填充字符串的右侧,使字符串位数变为8的倍数 $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt:'.$decrypt.'<br>';

然后来个对比,看看这两个函数的速度:

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789";

if(PHP_VERSION<5.6){
    $start = microtime(true);
    for($i=0;$i<10000;$i++){
        $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    }
    echo 'mcrypt_time:'; echo microtime(true)-$start.'<br>';
    echo 'mcrypt_encrypt'.$a.'<br>';
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'
mcrypt_time:1.8425710201263
mcrypt_encryptO4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt123456789
openssl_time:0.023201942443848
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt123456789
'); echo 'mcrypt_decrypt'.$decrypt.'<br>'; } $start = microtime(true); for($i=0;$i<10000;$i++){ $len = strlen($data); if($len%8){ $data = str_pad($data,$len+8-$len%8,""); } $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); } echo "openssl_time:"; echo microtime(true)-$start . '<br>'; echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt'.$decrypt.'<br>';

[+++]

结果

[+++]

本文来自php7教程栏目,欢迎学习。

以上就是PHP7 openssl函数替换mcrypt函数加密解密方法的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

Error[8]: Undefined offset: 11, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

PHP7 openssl函数替换mcrypt函数加密解密方法

PHP7 openssl函数替换mcrypt函数加密解密

以下是两者的区别及openssl替换mcrypt的方法:

替代

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789"; //要加密的数据

if(PHP_VERSION<5.6){
    $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    echo 'mcrypt_encrypt:'.$a.'<br>';
    //rtrim 移除字符串右侧的空白字符
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'运行结果');
    echo 'mcrypt_decrypt:'.$decrypt.'<br>';
} //使用mcrypt函数来对比



$len = strlen($data);
if($len%8){
    $data = str_pad($data,$len+8-$len%8,"
mcrypt_encrypt:O4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt:123456789
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt:123456789
"); }//使用空字符填充字符串的右侧,使字符串位数变为8的倍数 $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt:'.$decrypt.'<br>';

然后来个对比,看看这两个函数的速度:

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789";

if(PHP_VERSION<5.6){
    $start = microtime(true);
    for($i=0;$i<10000;$i++){
        $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    }
    echo 'mcrypt_time:'; echo microtime(true)-$start.'<br>';
    echo 'mcrypt_encrypt'.$a.'<br>';
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'
mcrypt_time:1.8425710201263
mcrypt_encryptO4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt123456789
openssl_time:0.023201942443848
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt123456789
'); echo 'mcrypt_decrypt'.$decrypt.'<br>'; } $start = microtime(true); for($i=0;$i<10000;$i++){ $len = strlen($data); if($len%8){ $data = str_pad($data,$len+8-$len%8,""); } $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); } echo "openssl_time:"; echo microtime(true)-$start . '<br>'; echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt'.$decrypt.'<br>';

结果

[+++]

本文来自php7教程栏目,欢迎学习。

以上就是PHP7 openssl函数替换mcrypt函数加密解密方法的详细内容,)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)

PHP7 openssl函数替换mcrypt函数加密解密方法_PHP_内存溢出

PHP7 openssl函数替换mcrypt函数加密解密方法

PHP7 openssl函数替换mcrypt函数加密解密方法,第1张

PHP7 openssl函数替换mcrypt函数加密解密方法

PHP7 openssl函数替换mcrypt函数加密解密

以下是两者的区别及openssl替换mcrypt的方法:

替代

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789"; //要加密的数据

if(PHP_VERSION<5.6){
    $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    echo 'mcrypt_encrypt:'.$a.'<br>';
    //rtrim 移除字符串右侧的空白字符
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'运行结果');
    echo 'mcrypt_decrypt:'.$decrypt.'<br>';
} //使用mcrypt函数来对比



$len = strlen($data);
if($len%8){
    $data = str_pad($data,$len+8-$len%8,"
mcrypt_encrypt:O4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt:123456789
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt:123456789
"); }//使用空字符填充字符串的右侧,使字符串位数变为8的倍数 $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt:'.$decrypt.'<br>';

然后来个对比,看看这两个函数的速度:

$key = '-2i61^';
$iv = '&11r2(*3';

$data = "123456789";

if(PHP_VERSION<5.6){
    $start = microtime(true);
    for($i=0;$i<10000;$i++){
        $a= base64_encode(mcrypt_encrypt(MCRYPT_3DES,$key,$data,MCRYPT_MODE_CBC,$iv));
    }
    echo 'mcrypt_time:'; echo microtime(true)-$start.'<br>';
    echo 'mcrypt_encrypt'.$a.'<br>';
    $decrypt = rtrim(mcrypt_decrypt(MCRYPT_3DES,$key,base64_decode($a),MCRYPT_MODE_CBC,$iv),'
mcrypt_time:1.8425710201263
mcrypt_encryptO4/3PssvAkrYtIlhbQEr+g==
mcrypt_decrypt123456789
openssl_time:0.023201942443848
openssl_encrypt:O4/3PssvAkrYtIlhbQEr+g==
openssl_decrypt123456789
'); echo 'mcrypt_decrypt'.$decrypt.'<br>'; } $start = microtime(true); for($i=0;$i<10000;$i++){ $len = strlen($data); if($len%8){ $data = str_pad($data,$len+8-$len%8,""); } $b = base64_encode(openssl_encrypt($data,'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv)); } echo "openssl_time:"; echo microtime(true)-$start . '<br>'; echo "openssl_encrypt:".$b. '<br>'; $decrypt = openssl_decrypt(base64_decode($b),'DES-EDE3-CBC',$key,OPENSSL_RAW_DATA|OPENSSL_NO_PADDING,$iv); echo 'openssl_decrypt'.$decrypt.'<br>';

结果

本文来自php7教程栏目,欢迎学习。

以上就是PHP7 openssl函数替换mcrypt函数加密解密方法的详细内容,

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/679817.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-20
下一篇 2022-04-20

发表评论

登录后才能评论

评论列表(0条)

保存