3

我正在尝试加密分布在多台服务器上的 Windows 应用程序上的连接字符串(我认为类似于网络场)。连接字符串实际上位于一个名为“ConnectionStrings.config”的单独文件中,我使用我的域/用户帐户作为远程桌面登录来执行此操作,该帐户当前具有管理员权限。

  1. 将我的连接字符串引用到外部文件“ConnectionStrings.config”

    <connectionStrings configSource="ConnectionStrings.config"/>

  2. 将 ConnectionStrings.config 复制到名为 web.config 的新文件中

  3. 添加打开和关闭<configuration>标签
  4. 添加<configProtectedData>部分
  5. 现在我的 web.config 看起来像这样:

    <!-- This file contains the connection string referenced by the app.config file --> <configuration> <configProtectedData> <providers> <add keyContainerName="SecurityKeys" useMachineContainer="false" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" name="AppEncryptionProvider" type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> </providers> </configProtectedData> <connectionStrings> <add name="MyConnectionString" connectionString="Data Source=MyServer; Initial Catalog=MyDatabase;Persist Security Info=True;User ID=**MyId**;Password=**MyPwd**" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>

  6. 在管理控制台中创建容器

    E:\Program Files\MyApplication>aspnet_regiis -pc "SecurityKeys" -exp Microsoft (R) ASP.NET RegIIS version 4.0.30319.18408 Administration utility to install and uninstall ASP.NET on the local machine. Copyright (C) Microsoft Corporation. All rights reserved. Creating RSA Key container... Succeeded!

  7. 在管理控制台中加密 web.config

    E:\Program Files\MyApplication>aspnet_regiis -pef "connectionStrings" "." -prov "AppEncryptionProvider" Microsoft (R) ASP.NET RegIIS version 4.0.30319.18408 Administration utility to install and uninstall ASP.NET on the local machine. Copyright (C) Microsoft Corporation. All rights reserved. Encrypting configuration section... Succeeded!

  8. 将该部分移回应用程序配置文件。

  9. 将加密部分复制回 ConnectionStrings.config 文件:

    <connectionStrings configProtectionProvider="AppEncryptionProvider"> <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>**crazyencryptionstring!**</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>**anothercrazystring!**</CipherValue> </CipherData> </EncryptedData> </connectionStrings>

  10. 运行应用程序 - 没有问题!!!!

  11. 在管理控制台中导出密钥

    E:\Program Files\MyApplication>aspnet_regiis -px "SecurityKeys" ".\SecurityKeys.xml" -pri Microsoft (R) ASP.NET RegIIS version 4.0.30319.18408 Administration utility to install and uninstall ASP.NET on the local machine. Copyright (C) Microsoft Corporation. All rights reserved. Exporting RSA Keys to file... Succeeded!

  12. 使用该应用程序将密钥文件复制到另一台服务器。

  13. 在管理控制台中导入密钥

    E:\Program Files\MyApplication>aspnet_regiis -pi "SecurityKeys" "SecurityKeys.xml" Microsoft (R) ASP.NET RegIIS version 4.0.30319.18408 Administration utility to install and uninstall ASP.NET on the local machine. Copyright (C) Microsoft Corporation. All rights reserved. Importing RSA Keys from file.. Succeeded!

  14. 复制新的 ConnectionStrings.config 文件,我认为该文件将使用导入的密钥

  15. 运行应用程序(与我进行导入时相同的登录名) - UGH,失败

    Failed to decrypt using provider 'AppEncryptionProvider'. Error message from the provider: The RSA key container could not be opened. (E:\Program Files\MyApplication\ConnectionStrings.config line 4)

  16. 以管理员身份运行应用程序 - 失败的结果相同。

  17. 将权限更改为非常开放

    E:\Program Files\MyApplication>aspnet_regiis -pa "SecurityKeys" "EVERYONE" -full Microsoft (R) ASP.NET RegIIS version 4.0.30319.18408 Administration utility to install and uninstall ASP.NET on the local machine. Copyright (C) Microsoft Corporation. All rights reserved. Adding ACL for access to the RSA Key container... Succeeded!

  18. 运行它并....同样的问题

  19. 寻求帮助!


更多信息

好的,也许 ProcMon 的这个输出会给帮助我的人提供进一步的见解。我添加了一些过滤,并将工作的非加密版本与崩溃的加密版本进行了比较。过滤器设置为仅包括我的应用程序并排除以下任何结果:

  1. 成功

  2. 未找到名称

  3. 文件结束

  4. 重新解析

  5. 只有读者锁定文件

  6. 缓冲区溢出。

这就是我剩下的 - 所有加密的东西!!!显然,dm0747 是我,应用程序在 E:\POWERWeb\General 中有文件

在此处输入图像描述

4

0 回答 0