You can easily encrypt any section of the .NET configuration, not only in ASP.NET, as it seems to many developers, but absolutely also in other applications.
Check out Jon Galloway's blog post on the topic - well read!
Using this approach, you can encrypt the <connectionStrings> section - and to make it even easier, you can also screen this section into a separate file.
So, in your app.config for your Winforms application, you should:
<connectionStrings configSource="ConnectionStrings.config" />
and the same will be in your web.config for your web application, and the referenced file will only contain <connectionStrings> and can be encrypted. Download the appropriate connection string from your configuration and pass it to your DbContext constructor, and everything will be fine.
source share