ASP.NET Core DPAPI PersistKeyToFileSystem 加密密钥

4

我正在使用ASP.NET Core DPAPI。当前使用的密钥是未保护的。 文档中显示了一个示例,显示了加密的密钥,但我无法弄清楚用于此的api设置是什么。

我正在使用以下内容:

services
.AddDataProtection()
.SetApplicationName("MyApp")
.SetDefaultKeyLifetime(TimeSpan.FromDays(3))
.PersistKeysToFileSystem(new DirectoryInfo("C:\MyDir"));

以下是生成的 XML 文件的节选内容:
    <descriptor>
      <encryption algorithm="AES_256_CBC" />
      <validation algorithm="HMACSHA256" />
      <masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
        <!-- Warning: the key below is in an unencrypted form. -->
        <value>123345689...0987654321</value>
      </masterKey>
    </descriptor>
  </descriptor>

我希望磁盘持久化密钥也能被加密。我该如何实现这一点? 这个文档展示了一个使用加密密钥的示例。 需要哪些API方法调用才能生成具有加密密钥的xml密钥文件?
1个回答

2
目前有三种方法可用于在将密钥持久化到存储之前对其进行加密。 例如,您可以通过以下方式扩展示例:ProtectKeysWithDpapi()
services
.AddDataProtection()
...
.PersistKeysToFileSystem(new DirectoryInfo(@"C:\MyDir"))
.ProtectKeysWithDpapi();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接