Where to encrypt/decrypt my data?

后端 未结 3 1300
情深已故
情深已故 2021-01-31 23:41

I\'m using Symfony 2 with Doctrine 2.

I need to encrypt a field in my entity using an encryption service, and I\'m wondering where should I put this logic.

I\'m

3条回答
  •  醉话见心
    2021-02-01 00:21

    richsage's answer was pretty good, except I wouldn't register the custom type in the bundle class file. It's recommended that you use the config.yml like so:

    # ./app/config/confi
    doctrine:
        dbal:
            driver:   "%database_driver%"
            {{ etc, etc }}
            types:
                encrypted_string: MyCompany\MyBundle\Type\EncryptedStringType
    

    Then just make sure in your EncryptedStringType class you specify the getName function to return encrypted_string.

    Now in your model definition (or annotation) you can use the encrypted_string type.

提交回复
热议问题