Reputation: 20068
I have a console application in which I have some connection strings which are encrypted as shown below:
<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>soemvalue here</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>some valye here</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
I try to access the connection string using the console application like this:
var connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
I get the following error:
Failed to decrypt using provider 'RsaProtectedConfigurationProvider'. Error message from the provider: The RSA key container could not be opened.
When I try to access the same connection string from app.config without decryption then it works fine. Is there any problem with the encryption? I thought that after encryption I just have to fetch the connection string in normal manner and it will decrypt automatically.
Upvotes: 2
Views: 6971
Reputation: 868
You need to encrypt and decrypt on the same machine, or you need to export / import the key.
See this article:
Upvotes: 4