我已使用 Always Encrypted 加密了 Azure SQL 数据库中的一些列和存储在 Azure Key Vault 中的列主 key ,但我在使用 Entity Framework 从我的应用程序访问它们时遇到问题。
最近有一个MSDN article和一个older blog post解释了如何设置 SqlConnection 以使用 Azure Key Vault 的 Always Encrypted,因此我猜测可以使用 constructor 创建普通的 DbContext接受DbConnection
。
问题是我正在使用 IdentityDbContext
,它没有该构造函数 - 唯一的 constructor需要 DbConnection
也需要 DbCompiledModel
,这超出了我目前的薪资水平。
谁能解释一下如何设置 IdentityDbContext
来使用 Key Vault?
最佳答案
EF 团队似乎有一个 test that uses encryption .
var connectionStringBuilder = new SqlConnectionStringBuilder(SqlServerTestStore.CreateConnectionString("adventureworks"))
{
Encrypt = encryptionEnabled
};
var options = new DbContextOptionsBuilder();
options.UseSqlServer(connectionStringBuilder.ConnectionString);
using (var context = new AdventureWorksContext(options.Options))
{
context.Database.OpenConnection();
Assert.Equal(ConnectionState.Open, context.Database.GetDbConnection().State);
}
TODO:测试 IdentityDbContext 构造函数公开与 AdventureWorksContext 相同的构造函数。
关于sql-server - 将 Always Encrypted 与 Entity Framework 和 Azure Key Vault 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37732871/