I'm using application level encryption to protect sensitive data. I need to encrypt the field before I store it in the physical database and I need to decrypt it before I show it on the user interface.
I'm applying the Repository pattern in the application.
Does the data encryption/decryption code belong inside or outside the Repository class?
My current thoughts are that when the data is at rest, encryption is an aspect of the repository and the service class using the repository should not be cluttered with this encryption code.
The service class is responsible for validation and business logic, but the encryption algorithm and how the data is stored at rest is up to the repository implementation.
Is this a reasonable practice or am I missing something?