PHP如何使用 key 编码/解码文本?

标签 php decode encode

代码:

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

它编码$string。但是如何解码$result呢?

请告诉我如何解码 $result

最佳答案

解密:

//Encryption
$result = mcrypt_ecb (MCRYPT_3DES, 'test', $string, MCRYPT_ENCRYPT);
//Decryption
$decrypt_result = mcrypt_ecb (MCRYPT_3DES, 'test', $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, $key, $iv);
$decrypted = mdecrypt_generic($cipher,$encrypted);
mcrypt_generic_deinit($cipher);

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

关于PHP如何使用 key 编码/解码文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23889885/

相关文章:

php - 为什么超时不工作linux服务器

PHP 仅对数字和字符进行字符串编码/解码

java - 为什么我不能从方法声明中单独导入?(java)

python - 'UCS- 2' codec can' t 对位置 61-61 中的字符进行编码

windows - 如何在 Windows 中循环处理 FFMpeg?

php - mysql全选,按orderid分组

php - RewriteRule 斜杠单一重定向

PHP 单例和继承

Python 3 相当于 Python 2 str.decode ('hex' )

python - 将 base64 编码的字符串转换为十六进制 int