CodeIgniter Forums
encrypt->decode does NOTHING. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: encrypt->decode does NOTHING. (/thread-10136.html)



encrypt->decode does NOTHING. - El Forum - 07-20-2008

[eluser]loathsome[/eluser]
Hello.

I try to decode a string using the encrypt library, but nothing happens. I pasted from the manual as well
Quote:$encrypted_string = 'APANtByIGI1BpVXZTJgcsAG8GZl8pdwwa84';

echo $this->encrypt->decode($encrypted_string);

And I get nothing. I have set an encryption key in the config file. What the heck is this?? Encode works just fine.

Thanks.


encrypt->decode does NOTHING. - El Forum - 07-20-2008

[eluser]Derek Allard[/eluser]
Be sure you are decode I a string that you'd previously encoded.

What happens if you run this?
Code:
function test()
    {
        $this->load->library('encrypt');

        $msg = 'One day, the robots will come for us';
        $encrypted_string = $this->encrypt->encode('My secret message');
        $plaintext_string = $this->encrypt->decode($encrypted_string);

        echo "<p>The original string was: $msg</p>";
        echo "<p>Encoded, that becomes: $encrypted_string</p>";
        echo "<p>If I take that encoded version, and run it through decode() I get: $plaintext_string</p>";
    }



encrypt->decode does NOTHING. - El Forum - 07-20-2008

[eluser]loathsome[/eluser]
Hi Derek.

Your example does work, luckily, but the one copy/pasted from the user guide does not - which explains my confusion. I also tried it out with my own encoded strings, but after running your code everything seems to work now. (Maybe you snuck some evil robots in there? :O)

Anyway, you better fix up the documentation then. When I encode "My secret message", I get
Quote:4QLohIc7WHMrYV5fDpOCLwahLv2uDLpTbQ9YqbyFOKeje0cNhBf8pXcixIxtZensrjW+3Py7o6liqD6KNc+jgIlryfQtk3IWqiLeMX+jNotJbLQRCDJWDdcfxfRkHLkM

Maybe it's left from an older version or something Smile


encrypt->decode does NOTHING. - El Forum - 07-20-2008

[eluser]Pascal Kriete[/eluser]
loathsome, the message depends on your encryption key. That way someone who doesn't know your key cannot decrypt it - which is the goal. The user guide doesn't say what encryption key it used, so you cannot decrypt that example. Make sense?


encrypt->decode does NOTHING. - El Forum - 07-20-2008

[eluser]loathsome[/eluser]
Ah, of course!! I have no idea how I didn't think about that, and it makes perfect sense. *bashes head against wall*.

Stupid me Smile