2

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

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

http://www.databasejournal.com/features/mssql/exploration-of-sql-server-2016-always-encrypted-part-1.html

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.

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

    [Encrypted]
    public string Username { get; set; }

    [Encrypted]
    public string Password { get; set; }

    [Encrypted]
    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)
    {
        modelBuilder.UseEncryption(this._provider);
    }
}

refer this site:

https://docs.microsoft.com/en-us/sql/relational-databases/security/encryption/develop-using-always-encrypted-with-net-framework-data-provider?view=sql-server-ver15

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