[英]PHP decrypt mcrypt (MCRYPT_RIJNDAEL_128)
i have the function: 我有功能:
$cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$key256 = 'b4:18:d1:ed:228d';
$iv = 'b4:18:d1:ed:228d';
$plainText = "blabla";
mcrypt_generic_init($cipher, $key256, $iv);
$cipherText256 = mcrypt_generic($cipher,$plainText );
$cipherHexText256 =bin2hex($cipherText256);
echo $cipherHexText256;
and im getting the result: 我得到的结果:
b752e34496e86853569370b8323eb601
Can someone help me and give me the function to decrypt the result to the plaintext again? 有人可以帮助我,给我提供再次将结果解密为纯文本的功能吗?
Kind regards 亲切的问候
<?php
/* Open the cipher */
$td = mcrypt_module_open('rijndael-256', '', 'ofb', '');
/* Create the IV and determine the keysize length, use MCRYPT_RAND
* on Windows instead */
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($td);
/* Create key */
$key = substr(md5('very secret key'), 0, $ks);
/* Intialize encryption */
mcrypt_generic_init($td, $key, $iv);
/* Encrypt data */
$encrypted = mcrypt_generic($td, 'This is very important data');
/* Terminate encryption handler */
mcrypt_generic_deinit($td);
/* Initialize encryption module for decryption */
mcrypt_generic_init($td, $key, $iv);
/* Decrypt encrypted string */
$decrypted = mdecrypt_generic($td, $encrypted);
/* Terminate decryption handle and close module */
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
/* Show string */
echo trim($decrypted) . "\n";
?>
taken from http://php.net/manual/de/function.mcrypt-module-open.php 取自http://php.net/manual/de/function.mcrypt-module-open.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.