views:

238

answers:

1

Err.... like the question says.

How do I go about encrypting and then decrypting data that 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!

+1  A: 

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

DavidYell
Just to clarify, while afterFind/beforeSave are the correct approach, you only really need to bundle the code in a behavior if you plan on reusing this functionality in more than one model.
deizel