在我的应用程序中,我配置了数据保护机制,将生成的密钥存储在系统上的文件中:
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo(@"C:\keys"));而且它正在发挥作用。在我的“key”目录中,生成了一个包含如下内容的文件:
<?xml version="1.0" encoding="utf-8"?>
<key id="7139a96c-1d75-468f-a343-1d0d363650a7" version="1">
<creationDate>2019-04-22T14:27:34.9530001Z</creationDate>
<activationDate>2019-04-22T14:27:34.9359888Z</activationDate>
<expirationDate>2019-07-21T14:27:34.9359888Z</expirationDate>
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<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>JzykGRqFcYWq3MPQAyuXe4IlEGrj62ghnCEMMuv0YzRKmHjzlfSOcbnk7+cJpDGe0PLKfCwcNPfOKplqu1xfDg==</value>
</masterKey>
</descriptor>
</descriptor>
</key>现在我不明白一件事。我使用的是AES_256_CBC算法,但是密钥的长度是88个字符而不是32个字符。
所以我想出了密钥是用base64编码的。解码后,我们得到以下密钥:
“‘<¤qªÜÃÐ+{%jãëh!!2ëoloc4Jxóoloqääç¤1ÐòÊ|,4÷Î*j»_”
但它有66个字符,而不是32个字符。如何获得32位的AES对称密钥,因为我不理解ASP.NET核心是如何保存这个密钥的。
我将非常感谢您的帮助。
发布于 2019-06-07 14:49:07
密钥环中的'masterKey‘值似乎实际上是一个64字节的密钥派生密钥(KDK),而不是一个简单的base64密钥。
这意味着您可以从此KDK派生AES子密钥。这就是默认的ManagedAuthenticatedEncryptor.cs实现的方式。
如果我可以找到或编写一个独立的键提取函数,我会在这里添加它(除非有人抢先一步)。
希望这能有所帮助!
编辑1:
经过五天的工作,我已经能够将AspNetCore codebase的不同部分组合到this monstrosity中。如果AAD值正确,这将从KDK中提取AES和SHA256密钥,然后解密ASPNetCore共享cookie有效负载。
发布于 2020-10-12 22:42:04
为了帮助你,我写了一个实现,将数据保护密钥环存储在Azure密钥库中。我在这里写了一篇博文:
Storing the ASP.NET Core Data Protection Key Ring in Azure Key Vault
然而,问题是为什么需要在字节/Base64级别上处理单个键?要将它们存储在其他地方,只需实现IXmlRepository接口,使用它就非常简单。不需要处理原始密钥字节。
https://stackoverflow.com/questions/55796400
复制相似问题