Entity Framework Core extension to encrypt and decrypt entities using AES mode CBC and PKCS7 padding.
On the entity use [Encrypted]
attribute on propeties that needs to be encrypted and decrypted. It will only works on string
properties.
public class Message
{
public int Id { get; set; }
[Encrypted]
public string Text { get; set; }
}
All examples can be found in MessagesController
in the TestAPI project.
await context.AddEncryptAsync(message, encryptionKey);
await context.SaveChangesAsync();
var result = await context.Messages.AsNoTracking().ToListDecryptAsync(encryptionKey);
var result = await context.Messages.AsNoTracking()
.Where(x => x.Id == id)
.Select(x => x.Text.Decrypt(encryptionKey))
.FirstOrDefaultAsync(key);