c# - ASP.NET Core 中的 key 加密

标签 c# asp.net-core cryptography data-protection

我在 ASP.NET Core 2.0 应用程序中使用 Microsoft.AspNetCore.DataProtection 来保护数据。对于默认设置,我在 Startup.cs 文件中添加了以下代码

public IServiceProvider ConfigureServices(IServiceCollection services)
    {
        services.AddDataProtection().ProtectKeysWithDpapi();
        ...
        ...
    }

但是该代码会引发错误:

InvalidOperationException: The 'IXmlRepository' instance could not be found. When an 'IXmlEncryptor' instance is set, a corresponding 'IXmlRepository' instance must also be set.

我在这个实现中遗漏了什么吗?

最佳答案

您指定了如何加密 key (IXmlEncryptor 的 Windows DPAPI 实现)但您没有指定保存加密 key 的位置(IXmlRepository)。有多种选项可以保留 key ,例如文件系统、注册表或云中的某个远程位置。

尝试使用 PersistKeysToFileSystem()PersistKeysToRegistry()。建议你看看at the documentation关于 ASP.NET Core 数据保护配置。

关于c# - ASP.NET Core 中的 key 加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55000472/

相关文章:

c# - Enyim Memcached Client 不写/读数据

c# - MMC 管理单元和 .Net 4.x

azure - Azure 网站上的 .NET CORE 3.1 : 500. 37 ANCM 无法在启动时间限制内启动

visual-studio - Visual Studio 2017 目标框架中未列出 Asp Net Core 2.1

c# - 我可以从 asp.net 5 中的单例实例中解析范围内的实例吗

c# - 创建使用一个 foreach 而不是多个的方法

c# - System.DirectoryServices 很慢

java-me - 网络安全

c# - 如何在 Windows 上的 .net 框架中使用来自 ECC X509 证书的公钥加密数据?

java - 尝试验证签名时,抛出异常 : java. io.IOException:序列标记错误