I am currently designing a web application where the data needs to be stored encrypted.

Planned technologies used:

  • ASP.NET Core API
  • ASP.NET Core Entity Framework
  • MS SQL Server 2016
  • any Web Frontend

Because of the specification we need to store all data encrypted in the database.

Which would be a good approach to achieve this while still be able to use the Entity Framework & LINQ, so the developer does not have to take care about the encryption.

Is it possible to encrypt the whole database?

To clarify, the encryption between the web frontend & the API isn't something that's related to this question.

2 Answers 2


Encryption algorithm are slow so, Encrypting whole database is going to affect performance. Encrypting whole database require more space. Good Approach is that encrypt crucial data like Username ,Password ,Contact-number, Email etc. Good approach is that encrypt data while inserting into database and decrypt it while reading. you can create library for encryption operation. you can use Aes provider You can add [Encrypted] attribute to you property.

public class Student
    public int Id { get; set; }

    public string Username { get; set; }

    public string Password { get; set; }

    public int Email{ get; set; }

public class DatabaseContext : DbContext
    // Get key and IV from a Base64String or any other ways.
    // You can generate a key and IV using "AesProvider.GenerateKey()"
    private readonly byte[] _encryptionKey = ...; 
    private readonly byte[] _encryptionIV = ...;
    private readonly IEncryptionProvider _provider;

    public DbSet<UserEntity> Users { get; set; }

    public DatabaseContext(DbContextOptions options)
        : base(options)
        this._provider = new AesProvider(this._encryptionKey, this._encryptionIV);

    protected override void OnModelCreating(ModelBuilder modelBuilder)

refer this site:



SQL 2016 came up with the new encryption feature. Please take a look.


It is not a good idea to encrypt a whole database for the performance reasons. Go through the article. The encryption & decryption happens with the help of ADO.NET layer.

  • ASP.Net Core currently does not support Always Encrypted (yet) - stackoverflow.com/a/41175581/5235385
    – phhbr
    Commented Apr 7, 2017 at 11:48
  • Yeh, you may be right.. Did you check it yourself. MS couldn't have missed this important feature.
    – Karan
    Commented Apr 7, 2017 at 11:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.