Encrypt the connectionStrings section of your web.config on your server, and then add this encrypted section to your web file. [CONFIGURATION_FOR_SERVER] .config. The key is the first line that says replacing the connectionStrings part of your original web.config with this new encrypted value. You will need a new conversion file for each server you publish to. Visual Studio will raise a warning (not an error), i.e.
Warning 15 The element 'connectionStrings' has invalid child element 'EncryptedData' in namespace 'http://www.w3.org/2001/04/xmlenc#'. List of possible elements expected: 'add, remove, clear'. C:\DevTFS\YourProject\Web.Stage.config 14 6 YourProject
about the format of this conversion file - I did not find the correct syntax to get around this, so I am open to suggestions, but it still works, so I'm happy. Full blog entry on this subject: http://randomdotnetnuggets.blogspot.com.au/2013/05/publishing-encrypted-connection-strings.html
<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider" xdt:Transform="Replace"> <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>t8p7aOZTjMo...zE6FAAI=</CipherValue> </CipherData> </EncryptedKey> </KeyInfo> <CipherData> <CipherValue>Vy1TZWY8....ic+Qg6T7U</CipherValue> </CipherData> </EncryptedData>
source share