Cakephp - how to encrypt and then decrypt data that is being stored and retrieved from the database
Err.... like the question says.
How do I go about encrypting and then decrypting data th开发者_运维知识库at is being stored and retrieved from the database.
By the way it's not just for storing a password which has been md5ed, I need to retrieve the data too.
Thanks!
I'd do this in the various before methods in my models, or better still create a before method in my app controller which encrypted and decrypted data.
afterFind(); //decrypt
beforeSave(); //encrypt
Would be the methods that I would choose.
PS, I should mention Behaviours here also really, as that's the ideal 'Cake way' to achieve this kind of thing, http://book.cakephp.org/view/595/Creating-Behaviors
there are several articles in cakephp to store and retrieve your table fields in encrypt/decrypt values automatically or manually
take a look at
http://bakery.cakephp.org/articles/xemle/2008/08/26/cipher-behavior
and
http://bakery.cakephp.org/articles/utoxin/2009/08/01/cryptable-behavior
with these way you can customize what field(s) you want to encrypt the data and also how to decrypt. You will need MCRYPT module in your php
精彩评论