Reputation: 5799
I'm working on a project where security matters on a number of fields in my Entity Models. I'm looking for a way I might be able to inject some custom logic with EF Core (with a MariaDb SQL Server) to encrypt data going into the database and decrypt it as it comes out automatically. Essentially I'm looking to do something similar to the following where I may have a field that contains sensitive information that could be either a string or DateTime in my model, but needs to be as an encrypted string in the database.
public class Customer
{
public string Id { get; set; }
public string Name { get; set; }
[Secure]
public DateTime DateOfBirth { get; set; }
[Secure]
public string StateIdNumber { get; set; }
public List<CreditCard> CreditCards { get; set; }
}
public class CreditCard
{
public string Id { get; set; }
[Secure]
public string CardNumber { get; set; }
[Secure]
public DateTime Expiration { get; set; }
[Secure]
public string CustomerId { get; set; }
public Customer Customer { get; set; }
}
Upvotes: 1
Views: 649
Reputation: 30375
If you're using SQL Server 2016, you can use the Always Encrypted feature. (I'm not sure if MariaDb SQL Server is a hosted version of Microsoft SQL Server or a different database entirely...)
Upvotes: 0