title: How to implement CakePHP's encrypt and decrypt functions into models?
body: <p>I am investigating encrypting and decrypting my data in my database using CakePHP. How do you guys secure your data in your database?</p>
  
  <p>A possible approach would be; 'saving' my (unencrypted) data via the model, which should encrypt specific data and save it into the database. When retrieving data via the model, it should decrypt the data and give it back to me.</p>
  
  <p>Another option would be; implementing the <code>encrypt</code> and <code>decrypt</code> functions in the specific entity (using the getters and setters). However, searching on specific fields would be harder (because you want to keep your code DRY)</p>
  
  <p>I know that <code>encrypt</code> and <code>decrypt</code> functions are available in Cake: <a href="https://book.cakephp.org/3.0/en/core-libraries/security.html" rel="nofollow noreferrer">https://book.cakephp.org/3.0/en/core-libraries/security.html</a></p>
  
  <p><strong>TLDR; How do I implement encryption and decryption the right way in CakePHP when I want to store my data secure?</strong></p>