CodeIgniter Forums
Issue with Encrypting - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Issue with Encrypting (/showthread.php?tid=76133)



Issue with Encrypting - illmaren - 04-15-2020

Hi,

I try to use the Encrypting Libary but the returning string everytime something like this:
Code:
1?dӑ??U?v??(?I??-???1??4R|?5K??k?Tu???`??X?^?l4??p@????G 6??QšC?X?h???O???o

and this makes decrypting obviously impossible..
My encoding is UTF-8 everywhere ( in Database and the File encoding )
I tried googling for a solution already but only found thing like doing it with base64_encode/decode but there the error persists..


RE: Issue with Encrypting - Leo - 04-16-2020

Hi, what do you mean impossible? It's in the guide, you gotta turn it into a string with bin2hex and store it in your code like this: $key = hex2bin(<your hex-encoded key>);

https://codeigniter.com/user_guide/libraries/encryption.html#encoding-keys-or-results


RE: Issue with Encrypting - illmaren - 04-16-2020

Still getting
Code:
Decrypting: authentication failed.

Code is just a quick and dirty version of it...so dont wonder about it Smile

PHP Code:
    /**
     * @param array $user
     */
    public function createUser(Array $user)
    {
        $user['user'] = bin2hex($this->encrypter->encrypt($user['user']));
        $user['salt'] = bin2hex($this->encrypter->encrypt($user['salt']));
        $user['email'] = bin2hex($this->encrypter->encrypt($user['email']));
        $this->db->table('users')->insert($user);
    }

    public function getUser()
    {
        $builder $this->db->table('users');
        $builder->where('id''1');
        $query $builder->get("1");
        $result $query->getResultObject();
        $result $result[0];

$user = new User();
$user->id $result->id;
$user->user $this->encrypter->decrypt(bin2hex($result->user));
$user->email $this->encrypter->decrypt(bin2hex($result->email));

        return $user;
    

Can be closed, solved the problem. You should'nt save your encrypted string into a varchar(100) coulmn :$


RE: Issue with Encrypting - jreklund - 04-17-2020

You should save it as BINARY or VARBINARY, then you don't need to turn it into HEX.


RE: Issue with Encrypting - InsiteFX - 04-18-2020

If this is for an Auth system you should be using php password_hash methods.

Paragon Initiative Enterprises Blog.

Implementing Secure User Authentication in PHP Applications with Long-Term Persistence (Login with "Remember Me" Cookies)

PHP Net.

PHP.NET - Password Hashing