开发者

Decrypting Text Using AES in CBC Mode

I have this code

$td = \mcrypt_module_open(\MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
            \mcrypt_generic_init($td, '12345678901234561234567890123456', '12345678901234567890123456789012');
            echo mdecrypt_generic(
                    $td,
                    \mcrypt_generic($td, "Testing")
            );

But the result is ˆ]Ië{ŒÕÌe}Q™‡ÿòø¬ÀÿÙ®»/› Why isnt the text being properly decrypted? I also tried base_64 encoding and decoding in the right places so i think the pr开发者_如何转开发oblem might be elsewhere.


You should reinitialize before decryption, i.e. call crypt_generic_init again. Also, after encryption is finished, you should call mcrypt_generic_deinit.


It's just a wild guess, but since you're using CBC mode, you probably need to reset the iv before you can decrypt it.

$td = \mcrypt_module_open(\MCRYPT_RIJNDAEL_256, '', MCRYPT_MODE_CBC, '');
$key = '12345678901234561234567890123456';
$iv =  '12345678901234567890123456789012';

\mcrypt_generic_init($td, $key, $iv);
$encrypted = \mcrypt_generic($td, "Testing");

\mcrypt_generic_init($td, $key, $iv);
echo \mdecrypt_generic($td, $encrypted);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜