1

I'm trying to encrypt values to be stored in a database for later retrieval and decryption. The simple solution appears to be to use accessor/mutator for the table.

protected function _setFirstName($first_name)
{
    return Security::encrypt($first_name, $this->key);
}
protected function _getFirstName($first_name)
{
    if ($this->_properties) {
        return Security::decrypt($first_name, $this->key);
    }
}

What I've noticed is that while the mutator does the conversion, before saving the accessor is reverting it, saving the value as the unencrytped original and not the encrypted value.

How do I get it to save the encrypted value?

Naidim
  • 6,918
  • 2
  • 23
  • 20
  • 1
    Mutators/Accessors are not ment to be able to handle transformations for data storage, that's rather a job for database type classes. **http://stackoverflow.com/questions/32260229/encyption-decryption-of-form-fields-in-cakephp-3** – ndm Jan 30 '17 at 18:50
  • Exactly what I was looking for, thank you! – Naidim Jan 30 '17 at 19:28

0 Answers0