I have a asp.net forms website which uses entity Framework. I need to encrypt the connection string in the web config so that it is not visible to people. I also need to decrypt the connection string for entity framework to use it.
I am following this article.
The did run the command aspnet_regiis -pef "connectionStrings" "C:\Projects\students\exams.UI" which generated replaced my original connectionstring
<connectionStrings>
<add name="StudentEntities" connectionString="metadata=res://*/StudentModel.csdl|res://*/StudentModel.ssdl|res://*/StudentModel.msl;provider=System.Data.SqlClient;provider connection string="data source=Server;initial catalog=Student;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
with the following connection string
<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>aXfgsT4DI=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>eCAX0N2hgsldWCTr</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
I use the following code to get the decrypt key back
Dim setting = ConfigurationManager.ConnectionStrings
Dim config As System.Configuration.Configuration = _
WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath)
Dim key As MachineKeySection = CType(config.GetSection("system.web/machineKey"), MachineKeySection)
DecryptionKey = key.DecryptionKey
ValidationKey = key.ValidationKey
how do I decrypt get the connection string settings and assign it to Entity Framework.