.NET Framework - Encrypt a Key in app.config

Asked By Ryan
12-Mar-10 02:06 PM
The following code encrypts the entire section of <appSettings> in app.config.
How do I encrypt only a Key (MyKey) in that section; not the entire section?
e.g.

Private Sub ProtectSection(ByVal sSectionName As [String])
Dim config As Configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim section As ConfigurationSection = config.GetSection(sSectionName)
If section IsNot Nothing Then
If Not section.IsReadOnly() Then

section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider")
section.SectionInformation.ForceSave = True
config.Save(ConfigurationSaveMode.Modified)
End If
End If
End Sub
Section.SectionInformation.ForceSave
(1)
RsaProtectedConfigurationProvider
(1)
GetSection
(1)
Encrypt
(1)
Shift
(1)
SSectionName
(1)
IsNot
(1)
MyKey
(1)
  Mr. Arnold replied to Ryan
12-Mar-10 04:20 PM
About the best you could do is come up with some kind of keyboard key
strokes encryption of  Shift-key, non Shift-key, Ctrl-Key, non Ctrl-key,
alpha, numeric, and special keys key combination sequence to come up with an
encrypted key for MyKeyValue.

You could get some kind of free Keylogger so you can see the results of the
keystrokes and make it a long sequence. The longer the sequence makes it
harder to crack.

You can use Google, as you might see some free code that will do it for you.
Create New Account
help
IsLocked = = false)) { / / Protect (encrypt) the "connectionStrings" section. section.SectionInformation.ProtectSection(provider); / / Save the encrypted section. section.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Full); } MessageBox.Show("ok"); } The info in the standard .NET exception the config file. Configuration config = null; config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConfigurationSection section = config.ConnectionStrings; section.SectionInformation.ForceSave = true; config.Save(ConfigurationSaveMode.Full); MessageBox.Show("ok"); } He's also able to do RSA
class UnhandledExceptionModule : IHttpModule { public void Dispose() { } public void Init(HttpApplication pContext) { UnhandledExceptionSection section = 3D UnhandledExceptionSectionHandler.GetSection(); . . . } } } O = F9 UnhandledExceptionSectionHandler.GetSection() : public static UnhandledExceptionSection GetSection() { return (UnhandledExceptionSection) ConfigurationManager.GetSection ("unhandledExceptionConfiguration"); } Tout est farpaitement configur = E9 au niveau du Web.config. Si j'appelle : UnhandledExceptionSection section = 3D UnhandledExceptionSectionHandler.GetSection(); dans Default.cs, j'ai bien mon objet section. Par contre, au niveau de ma to cast object of type 'WebUnhandledException.UnhandledExceptionSection' to type 'WebUnhandledException.UnhandledExceptionSection'. Super. . . Par contre, si GetSection() retourne un Object, = E7a marche, j'ai bien mon objet avec les valeurs attendues, et Delf ASP.NET - French Discussions InvalidCastException (1) EventHandler (1) EventArgs (1) Application (1) IHttpModule (1) GetSection (1) Site (1) Dispose (1) Bon. . . j'ai d = E9port = E9 le code de Init new EventHandler(this.OnUnhandledException); } private void OnUnhandledException(object sender, EventArgs e) { UnhandledExceptionSection section = 3D UnhandledExceptionSectionHandler.GetSection(); if (section.IsLoaded) { . . . Pourquoi ?! Merci. - - Delf it En fait, non : | - - Delf Bonjour Delf, As tu
WebConfigurationManager.GetSection in Medium Trust .NET Framework Is it possible for a medium trust web application to read the Membership providers? The following throws a SecurityException: MembershipSection membershipSection = (MembershipSection)WebConfigurationManager.GetSection("system.web / membership"); I have custom sections in my web.config where I specify requirePermission information in your case). If my understanding is wrong please correct me. Unfortunately, calling WebConfigurationManager.GetSection() method directly is not allowed in medium trust. To work it around I would like with no warranties, and confers no rights. - -- -- -- -- -- -- -- -- -- - microsoft.public.dotnet.framework.aspnet:73875 (MembershipSection)WebConfigurationManager.GetSection("system.web / membership but type = "System.Web.Configuration.MembershipSection, requirePermission = "false" the machine-level Perhaps you are not aware of this, but it *is* possible to call WebConfigurationManager.GetSection() method in medium trust. I already do this for a new section named galleryServerPro I false" / > Then I can access it like this: GalleryServerProConfigSettings _alleryServerProConfigSection = (GalleryServerProConfigSettings)System.Web.Configuration.WebConfigurationManager.GetSection("system.web / galleryServerPro"); This works in Medium Trust. All I want to do is access section is defined in the machine.config it violates the security policy when calling WebConfigurationManager.GetSection("system.web / membership"). = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = '¡­.the only answer is to use the XmlReader class (Linq is not Microsoft Online Support - -- -- -- -- -- -- -- -- -- - microsoft.public.dotnet.framework.aspnet:74316 (GalleryServerProConfigSettings)System.Web.Configuration.WebConfigurationMan ager.GetSection("system.web / galleryServerPro"); you I to Thanks for confirming that. And thanks also for the
WebConfigurationManager.GetSection in Medium Trust .NET Framework Is it possible for a medium trust web application to read the Membership providers? The following throws a SecurityException: MembershipSection membershipSection = (MembershipSection)WebConfigurationManager.GetSection("system.web / membership"); I have custom sections in my web.config where I specify requirePermission Server Pro (http: / / www.galleryserverpro.com) ASP.NET Discussions WebConfigurationManager (1) MembershipSection (1) SecurityException (1) GetSection (1) AllowOverride (1) Gallery (1) Llibre (1) Español (1) Bump. I am an MSDN subscriber if anyone can address the original question, I sure would appreciate it! Roger keywords: WebConfigurationManager.GetSection, in, Medium, Trust description: Is it possible for a medium trust web application to read