App.Config dosyasında bulunan connectionStrings bölümünü şifrelemek.
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=V10000-PC;Initial Catalog=SQLDB;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
Private Sub btnEncrypt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncrypt.Click
Dim str() As String = Application.ExecutablePath.Split("\")
Dim applicationName As String = str(str.Count - 1)
applicationName = applicationName.Replace("EXE", "exe")
Dim config As Configuration = ConfigurationManager.OpenExeConfiguration(applicationName)
If config.HasFile() Then
EncryptAppConfig(config)
End If
End Sub
Private Sub EncryptAppConfig(ByVal config As Configuration)
Dim section As ConnectionStringsSection = config.GetSection("connectionStrings")
If Not section.SectionInformation.IsProtected Then
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider")
End If
config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("connectionStrings")
End Sub