Welcome Guest, Not a member yet? Register   Sign In
Issue with Encrypting
#1

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..
Reply
#2

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/libra...or-results
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply
#3

(This post was last modified: 04-16-2020, 11:13 AM by illmaren.)

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 :$
Reply
#4

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

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
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB