How do I encrypt user data in my database for my ecommerce opencart site?

I have just built a custom coded opencart-based ecommerce site. I have several registration forms on the site for different types of users and I am saving their info in the database which is also used by a custom Customer Relationship Management system I have built in OpenCart (to track user purchases and behaviour on the website).

What I am worried about is that the data related to all my users is in text format in the database - if I open the db in a text editor or in phpmyadmin I can read anything I want. How do I encrypt this data in the database so that even if there were to be a hack attempt, this data would be safe.

By the way I already have an EV SSL Certificate installed on the website so traffic itself should be protected from prying eyes. My concerns are purely database related.

Please advise.

thanks in advance
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lcohanDatabase AnalystCommented:
"What I am worried about is that the data related to all my users is in text format in the database"

What about BEFORE data reaches and it is stored into the database? You must think for that one as well as most of the time that's where the "sniffers" are and hit you and read it before they get to read your database table(s) sensitive info. If they got that far....not good and I guess you get the idea so please also research that path as well and make it safe.

For database encryption you can use SQL own TDE and please see more details at links below:
badwolfffAuthor Commented:
I am using an EV SSL Certificate by Geotrust so I suppose sniffers are out of the question. All traffic in either direction is completely encrypted. At least that is what GeoTrust says and provides warranty against. Unless I am very much mistaken the certificate I have installed should do that, so please correct me if I am mistaken. This is the certificate I have:

By the way I see you have sent me links for doing this with Microsoft SQL server whereas I use MySQL server. Any ideas?
badwolfffAuthor Commented:
lcohanDatabase AnalystCommented: sorry being for so long focused on SQL only.

There's a list of possible encryption functions at link below

You can also create trigger for update and check there field accessable. Something like that:

  IF new.accessable = 0 THEN
    SET new.msg := ENCRYPT(new.msg, 'key');
    SET new.msg := DECRYPT(new.msg, 'key');

You also can update all existing records in you table with this query:

UPDATE table SET msg = IF(accessible = 0, ENCRYPT(msg, 'key'), DECRYPT(msg, 'key'));

And you can select records via PHP code like:

SELECT msg_id, user_id, time, IF(accessible = 0, DECRYPT(msg, 'key'), msg) msg
FROM table

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.