sql-server - 将 Always Encrypted 与 Entity Framework 和 Azure Key Vault 结合使用

标签 sql-server entity-framework azure-keyvault always-encrypted

我已使用 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/

相关文章:

azure - 如何在Visual Studio中使用MSI进行开发?

SQL服务器: Get total days between two dates

python - 让python等待存储过程完成执行

sql-server - 表变量错误: Must declare the scalar variable "@temp"

c# - 获取嵌套集合包含另一个集合中的项目的项目

c# - Entity Framework 代码优先,非空 setter 或 getter?

java - 使用 Java 的 Azure Key Vault 证书管理

mysql - Coldfusion 服务器映射到 SQL Server

c# - 第二次保存到上下文时继续获取 "A second operation started on this context before a previous operation completed"。

c# - 如何使用 app.config 将 Azure Key Vault 连接到 C# Windows 服务