加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

PHP如何用密钥编码/解码文本?

发布时间:2020-12-13 21:51:32 所属栏目:PHP教程 来源:网络整理
导读:码: $result = mcrypt_ecb (MCRYPT_3DES,'test',$string,MCRYPT_ENCRYPT); 它代码编码$string.但是如何解码$result? 请告诉我如何解码$result? 解决方法 解密: //Encryption$result = mcrypt_ecb (MCRYPT_3DES,MCRYPT_ENCRYPT);//Decryption$decrypt_res
码:

$result = mcrypt_ecb (MCRYPT_3DES,'test',$string,MCRYPT_ENCRYPT);

它代码编码$string.但是如何解码$result?

请告诉我如何解码$result?

解决方法

解密:

//Encryption
$result = mcrypt_ecb (MCRYPT_3DES,MCRYPT_ENCRYPT);
//Decryption
$decrypt_result = mcrypt_ecb (MCRYPT_3DES,$result,MCRYPT_DECRYPT);

您需要在参数中更改模式并传递加密值.

注意:自PHP 7.1.0起,mcrypt_generic()也已被弃用.

阅读手册:http://www.php.net/manual/en/function.mcrypt-ecb.php.

最好使用mcrypt_generic().

$cc = 'my secret text';
$key = 'my secret key';
$iv = '12345678';

$cipher = mcrypt_module_open(MCRYPT_BLOWFISH,'','cbc','');

mcrypt_generic_init($cipher,$key,$iv);
$encrypted = mcrypt_generic($cipher,$cc);
mcrypt_generic_deinit($cipher);

mcrypt_generic_init($cipher,$iv);
$decrypted = mdecrypt_generic($cipher,$encrypted);
mcrypt_generic_deinit($cipher);

echo "encrypted : ".$encrypted;
echo "<br>";
echo "decrypted : ".$decrypted;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读