我正在尝试使用加密连接字符串
aspnet_regiis -pef "connectionStrings" "C:\Proj"
它给了我一个加密的漂亮的加密字符串
但是,它可以通过运行轻松解密
aspnet_regiis -pdf "connectionStrings" "C:\Proj"
在这种情况下,它没有用。
我的要求只是想加密连接字符串,只有我可以解密它(但不是任何其他有权访问服务器或帐户的人)
发现默认aspnet_regiis是使用DPAPI获取KEY
并且使用自定义提供程序可以实现我想要的
然后我尝试了
创建自定义密钥
aspnet_regiis -pc "myKey" -exp
将其授予 iis 应用程序池
aspnet_regiis -pa "IIS AppPool\DPool"
加密它
aspnet_regiis -pef connectionStrings c:\project -prov "customProvider"
之后,connectionStrings 被正确加密。
但是,我发现没有办法消除自定义提供程序密钥和 web.config 之间的依赖关系
用户可以在 web.config 中看到类似的内容
<configProtectedData>
<providers>
<add name="customProvider"
type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,
 Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
keyContainerName="myKey"
useMachineContainer="true" />
</providers>
</configProtectedData>
<connectionStrings configProtectionProvider="customProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#tripledes-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>Rsa Key</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>ICeYUc4dqh2XkxcQzB5VQc7egRcJfPLNOgoJTveUJlEvc67dzGUO13TYiAe/X1bKvouSfUUba4SXX981bhf26Z79e03ht8PciFBrcRCTRvsYYtcN4c8jRMoHYRcfd1bSGs7uWueR2+//SCZihwR8sfU6g8HTaSit7e0sxkzlIGE=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>TRrubEXUzzhqFXXhTt3hjsvjHPqxcJENNlYNkNBMSDEhzlowdV10r/2W7ln38DiZU4Jt0gYUcHKt/dBAM1Y0vNlqctKQMF0hD4VxK5E27D+uynyvUjcLIzCOTtSq4MLbiimGo0NC9rB7wax3Wxmlx6SPeGo6RLkvM2GyjfzwKx7mGqodV9rgX7O7nb+8YVCJdMJsckMUcyZDYbxINl+LmUjv3kJFtU3/3dV3s0pSZfNGURau8JQf4+UI/XMXQrHiU6fbfMdb5GEsEUkqHJh2foEbAfBVAz7F7vMtwVZ+Vvue7bOyFub8rGbmLOLifnSuEp8krJitTg7wQ9Dwdb6BxQ==</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
在这种情况下,自定义密钥容器被暴露(我无法删除它,否则网站也无法访问解密连接字符串)
显然,大家还是可以执行命令解密连接字符串的
aspnet_regiis -pdf connectionStrings "C:\Proj"
这意味着即使我应用了自定义 RSA 密钥容器提供程序,问题仍然没有解决。
有什么我错过的吗?真的有一些我可以删除的依赖项,以便 ppls 无法通过运行 -pdf 解密连接字符串,同时 IIS 可以正确读取连接字符串吗?