Welcome Guest, Not a member yet? Register   Sign In
Encryption and Encryption_key
#1

I am just doing some tests and have got myself a bit confused on CI3 and encryption.

I encrypt a simple string like 'HelloWorld', call it $coded and store it in a database BLOB field.

I then, from a controller, read the blob field and call it $db_coded.

I compare $coded and $db_coded and the comparison fails.

BUT, if I decrypt $db_coded and compare it to 'HelloWorld', the comparison passes.

Why would that be? Is it something to do with the prepended length on the Blob field?

If later I need to do a lookup on the field I will need to encrypt the 'HelloWorld' to compare it to the Blob field, but that comparison is failing.

Thanks in advance for any help or advice and apologies if I have just missed something really daft :-)

Best wishes,

Paul.
Reply
#2

(03-24-2015, 04:52 AM)PaulD Wrote: I am just doing some tests and have got myself a bit confused on CI3 and encryption.

I encrypt a simple string like 'HelloWorld', call it $coded and store it in a database BLOB field.

First try your test with a database LONGTEXT field. Once you have it working then try it on BLOB.

(03-24-2015, 04:52 AM)PaulD Wrote: I then, from a controller, read the blob field and call it $db_coded.

I compare $coded and $db_coded and the comparison fails.

If you are trying to compare passwords is best to use CI hash functions. However if you need to decode the string at some point (like a usernme) but also need to make an encrypted comparation then use CI encryption library with ECB mode (less secure) that will allow you to compare encrypted strings. If they match the comparation will pass.

(03-24-2015, 04:52 AM)PaulD Wrote: BUT, if I decrypt $db_coded and compare it to 'HelloWorld', the comparison passes.

Of course... if the string and the $db_coded is decrypted it will be ok to compare and it will pass.

Read about switching to ECB mode on CI documentation before make any changes.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB