How do I encrypt (hide) an encryption-key variable without its value being shown in the ildasm (assembly) in C#/.NET
Posted on 2006-06-24
I have put a lot of effort in order to build a class that encrypt ConnectionString or any other key/value arument in the App.config configuration file.
The problem I am facing is that the EncrypKey variable (string) I am using to hold the encryption key is shown in the ildasm utility as a part of the class assembly.
This issue was never a problem in C++ or VB as they are nativ programming languages, but the C# in .NET anvironment is an "open source code" to all whome consirn :(
I will apretiate very much a good solution in order to finnish the task I am facing of encryption of ConnectionString to a data-base.
I hope the solution will not be to write a DLL in nativ programming language such as C++ or VB and in this machine-code DLL to put the encription key I am using in the C# program. I do not have the knowladge for doing such a task (connecting between C# program and C++ DLL) and it is like saying that C# has a prity big disadvantege on native languages.
Here is what the ildasm showing when I look at the assembley of the encripting class.
Please notic that "SuperSecret" is the encryption key I am using in order to encrypt and decrypt ConnectionString value in App.config file.
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
// Code size 46 (0x2e)
IL_0002: stfld class [System]System.ComponentModel.Container SetAppConfig.Form1::components
IL_0008: call instance void [System.Windows.Forms]System.Windows.Forms.Form::.ctor()
IL_000e: ldstr "App.config"
IL_0013: ldstr "ConnectionString"
IL_0018: ldstr "SuperSecret"
IL_001d: newobj instance void [iConUtils]iConUtils.appConfiguration::.ctor(string,
IL_0022: stfld class [iConUtils]iConUtils.appConfiguration SetAppConfig.Form1::AppConfig
IL_0028: call instance void SetAppConfig.Form1::InitializeComponent()
} // end of method Form1::.ctor