mcrypt_decrypt return strange code
<p>I tried to encrypt an array then decrypt it back to string by calling a function, it's seem return the correct value if I does all encrypt and decrypt at once time in the function, however, if I return the encrypt  value, then call the function again to decrypt  it will return me some strange code. </p>

<p>Example 1:</p>

<pre><code>public main()
{
    $dataArray = array("one"=&gt;1, "two"=&gt;2, "three"=&gt;3);
    $a = $this-&gt;encryptDecryptInfo(json_encode($dataArray),$this-&gt;key);
    var_dump($a);
}

public function encryptDecryptInfo($text,$key)
{
    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, 
    $text= base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CFB, $iv));
    return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($text), MCRYPT_MODE_CFB, $iv);       
}
</code></pre>

<p>This will return me the correct value which is <strong>string(27) "{"one":1,"two":2,"three":3}"</strong> </p>

<p>Example 2:</p>

<pre><code>public main()
{
    $dataArray = array("one"=&gt;1, "two"=&gt;2, "three"=&gt;3);
    $a = $this-&gt;encryptDecryptInfo(json_encode($dataArray),$this-&gt;key,"encrypt");       
    $b = $this-&gt;encryptDecryptInfo($a,$this-&gt;key,"decrypt");
    var_dump($b);
}

public function encryptDecryptInfo($text,$key,$type)
{
    $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CFB), MCRYPT_RAND);
    if($type == "encrypt")
        return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CFB, $iv));
    else return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($text), MCRYPT_MODE_CFB, $iv);      
}
</code></pre>

<p>However if I do my code in this way, it will return me strange value which is like this <strong>string(27) "�ÔérôŸY éXgíœÈÐN*éà±œCµÖ"</strong>  .</p>

<p>Deos anyone know why this is happen? Both encrypt and decrypt coding are the same for example 1 and example 2, but why it will return strange code in example instead? Any way to fix this issue?</p>
