Announcement

Collapse
No announcement yet.

How to encrypt data

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • item
    replied
    Hello telecastg,
    sorry i have not skill for this kind of .. and not understand :s ... but for me it's easy for someone have skill :

    1) common hook (orm entity maybe)
    2) check if field have attribute isEncrypted (like personalData or required or.... )
    3) then crypt data ..

    i have make search for "personalData" in openFiles in sublimeText.
    fieldManager and/or entity are i think where the solution can be ok.

    Regards

    Leave a comment:


  • telecastg
    replied
    Thanks item, it sounds a lot easier that having to code hooks !

    Do you know if this setting also takes care of the mechanism for entering the password and reading the encrypted file ?

    Leave a comment:


  • item
    replied
    Hello,
    nice thanks

    the best is in entityManager -> fieldAttribute -> checkbox : isEncrypted ..
    so it's outOfBox and we can decide witch is encrypted or not.

    i think it's not difficult to implement this

    Regards

    Leave a comment:


  • telecastg
    replied
    I would suggest to create an beforeSave hook for Contact entity like this:

    custom/EspoCustom/Hooks/Contact/ContactHooks.php
    Code:
    <?php
    
    namespace Espo\Custom\Hooks\Contact;
    
    use Espo\ORM\Entity;
    
    class ContactHooks extends \Espo\Core\Hooks\Base
    {
    
        public function beforeSave(Entity $entity, array $options=array())
        {    
            // get the un​​​​​​-encrypted description from the model
            $description = $entity->get('description');
    
            // encrypt the description field prior to storing in database
    $fileM = new \Espo\Core\Utils\File\Manager();
    $config = new \Espo\Core\Utils\Config($fileM);
            $descriptionHash = new \Espo\Core\Utils\PasswordHash($config);
            $encodedDescription = $descriptionHash->hash($description,true);
    
            // store the encoded description in the model
            $entity->set('description', $encodedDescription);
        }
    
    }
    Please note that this is similar to the code that I use to encode passwords for new users but haven't tested it actually encrypting the description field, so this code is good for writing encrypted data but you will need to follow tothewine suggestion and overwrite the get method in the service class for Contact to be able to read the field, but since I haven't done that myself, I can't provide any guidance about it.

    Please correspond to our efforts to help by posting your solution after you implement it, so other participants can benefit also.

    Cheers
    Last edited by telecastg; 01-11-2020, 04:11 AM.

    Leave a comment:


  • tothewine
    replied
    to save look for hooks in github documentation
    to read override get method in service class for your record

    Leave a comment:


  • CharliSTV
    started a topic How to encrypt data

    How to encrypt data

    Hi.
    I am trying to encrypt some data that I need to store in the database, but I don't know exactly which classes are responsible for the process of storing for example the field description for contact entity.

    Could you help me please?​​​​​​

    ​Thanks
Working...
X