Tema: App.config
Ver Mensaje Individual
  #4 (permalink)  
Antiguo 25/05/2012, 10:35
Avatar de Aquaventus
Aquaventus
 
Fecha de Ingreso: junio-2010
Ubicación: Lima-Peru , En el alba de la naturaleza
Mensajes: 2.105
Antigüedad: 14 años, 8 meses
Puntos: 267
Respuesta: App.config

Hola juanleonardo, para encriptar tu config usa esto :
Código vb:
Ver original
  1. Public Sub encriptar()
  2.  
  3.             Dim Directorio As String = "C:\RUTA DE TU ARCHIVO\MI_EXE.exe"
  4.             Dim provider As String = "DataProtectionConfigurationProvider"
  5.             Dim configuration As System.Configuration.Configuration = Nothing
  6.             Dim section As ConnectionStringsSection = Nothing
  7.  
  8.             Try
  9.                 configuration = ConfigurationManager.OpenExeConfiguration(Directorio)
  10.  
  11.                 If configuration IsNot Nothing Then
  12.  
  13.                     Dim changed As Boolean = False
  14.                     section = TryCast(configuration.GetSection("connectionStrings"), ConnectionStringsSection)
  15.  
  16.                     If section IsNot Nothing Then
  17.                         If (Not (section.ElementInformation.IsLocked)) And (Not (section.SectionInformation.IsLocked)) Then
  18.                             If Not (section.SectionInformation.IsProtected) Then
  19.                                 changed = True
  20.                                 ' Encrypt the section.
  21.                                section.SectionInformation.ProtectSection(provider)
  22.                             End If
  23.                         End If
  24.                         If changed Then
  25.                             ' Indicates whether the associated configuration section will be saved even if it has not been modified.
  26.                            section.SectionInformation.ForceSave = True
  27.  
  28.                             ' Save the current configuration.
  29.                            configuration.Save()
  30.                         End If
  31.                     End If
  32.                 End If
  33.  
  34.             Catch ex As Exception
  35.                 MsgBox(ex.Message)
  36.             End Try
  37.  
  38.         End Sub
Y para leer desencriptado(Pero no revela tus datos encriptados en el config) por ejemplo :
Código C:
Ver original
  1. public class Conexion
  2.     {
  3.         Configuration configuration = null;
  4.         ConnectionStringsSection section = null;
  5.  
  6.         public String GetConex()
  7.         {
  8.             try
  9.             {
  10.                 configuration = ConfigurationManager.OpenExeConfiguration(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.ToString()).Remove(0, 6) + "\\MI_EXE.exe");
  11.                 section = configuration.GetSection("connectionStrings") as ConnectionStringsSection;
  12.                 section.SectionInformation.UnprotectSection();
  13.                 section.SectionInformation.ForceSave = true;
  14.  
  15.                 return section.ConnectionStrings["cn1"].ConnectionString;
  16.                 //return ConfigurationManager.ConnectionStrings["cn1"].ConnectionString;
  17.             }
  18.  
  19.             catch (Exception ex)
  20.             {
  21.                 return ex.Message;
  22.             }
  23.         }
  24.     }
Pero sería recomendable que lo encriptaras en un custom action en el setup del aplicativo.
Saludos!.

PDT: Disculpa por ponerte en ambos lenguajes jajaja pero es que era lo unico que tenia a la mano.
__________________
Internet es tener todo el conocimiento global a tu disposición.
Desarrollo de Software - Ejemplos .Net