Web 应用程序中实现的代码优先迁移场景如何实现始终加密的概念?

How to implement the always encrypted concept for code first migration scenarios implemented in web applications?

我阅读了下面的博客,了解如何在我的应用程序中实现加密概念,但在我的应用程序中,我使用代码优先迁移概念在 Azure SQL 数据库上执行 CRUD 操作。但是这篇博客用 Azure SQL 数据库上的普通 SQL 查询解释了加密概念。

始终加密:保护 SQL 数据库中的敏感数据并将加密密钥存储在 Azure Key Vault

https://docs.microsoft.com/en-us/azure/sql-database/sql-database-always-encrypted-azure-key-vault

如何为 Web 应用程序中实现的代码优先迁移方案实现始终加密的概念?

正如这位官员 blog 提到的关于将 Always Encrypted 与 EF6 一起使用:

Entity Framework 6 was not designed from the start to work with the Always Encrypted feature of SQL Server 2016. However, a lot of effort has gone into making the feature work as transparently as possible with existing code.

对于 Code First 迁移方案:

Migrations will require substantial tweaking – Entity Framework is not aware of the Column Master Keys and Column Encryption and has no way to model them, so this needs to be compensated by user.

您可以从迁移代码中删除加密属性,ALTER TABLE 以添加加密列,然后 Update-Database.并且建议在处理加密列时使用 Migrations over Initializers,这可能包括使用初始数据为数据库做种。更详细的可以参考这个blog.