连接属性未从加密的连接字符串填充

时间:2016-07-09 21:55:53

标签: c# encryption

我知道有很多问题与此非常相似,我试图深入研究它们,但我无法找到我所处的确切情况。

在使用VS Express 2015的C#桌面应用程序中,我试图在应用程序的内部App.config中访问加密的连接字符串。当我以未加密的方式访问连接字符串时,一切都很好,但是当我尝试使用它加密时,

MasterConnection.ConnectionString = ConfigurationManager.ConnectionStrings["AD_Secure"].ConnectionString;

我得到一个空引用异常,我可以看到连接字符串没有进入ConfigManager要查找的集合。所以我很确信这个问题与我的App.config有关。我使用RSA默认值使用ProtectSection函数加密文件。我的配置文件如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
        <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>JbYu29BSx0QMQAK55TsO+BMqN8+4xqYSYMRsVVjGJ7aFabv3KIB7JlJIC+v5zX/JZphj2vtFq0JgRbR5dh4iF+DJ8aBEKegKaLAgXNiBD2qVye+kqZNuadBj0+vHpmIMgDdH1mUKdUsYJFHe7rvVxY9OO4WHY9FPppAAubeyM+I=</CipherValue>
                    </CipherData>
                </EncryptedKey>
            </KeyInfo>
            <CipherData>
                <CipherValue>3gjt/GHT6OCQwUBMy+f0B3RtfnbF1MV6HyO2QJaqqpw=</CipherValue>
            </CipherData>
        </EncryptedData>
    </connectionStrings>
</configuration>

1 个答案:

答案 0 :(得分:0)

谢谢大家的快速回复。有时您只需要与其他人交谈以正确处理您自己的想法。一旦我内化了加密功能,每个人都完美地工作。所以我想另一种思考方式是,当应用程序配置加密时会生成“私钥”,并且当程序在应用程序配置中看到保护提供程序时,会在运行时生成“公钥”。

相关问题