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
Şifreleme işleminden sonra App.config dosyamızdaki connectionStrings aşağıdaki gibi görünecektir.
<?xml version="1.0"?>
<configuration>
<connectionStrings configProtectionProvider="DataProtectionConfigurationProvider">
<EncryptedData>
<CipherData>
<CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAqbdVsE6YE0+z/rQQVSy7YgQAAAACAAAAAAAQZgAAAAEAACAAAAAcliGdlVDuLPI732CY3rC9zBGiuTCLUJLw0jP1FyM6DQAAAAAOgAAAAAIAACAAAACIZgtSUyg/EZKS29Q08blqx/yDSjGBpgVyPRsv0MVQidABAADtQ7P4LySuNpPiEJnNexjfeRbSJFFVuWOCSxbFhktZiwRJJJB6fEATyGf5kTea6dCD1gLVqimVLqR1KsbHgcmZhrYTE3s4A8revjYMQ17JbLM6aYg1fa1XqVw0+L/fjfgDD3SteJFIfpbaHyjZY3bJAB6g7qyqIvEajkQED6PkhFi3VCv4pxcwMwR5hITVkgLx/OGOiJXCv7J4jyG9JTrwcZTXyzr8lvlTQVs9lBV0NEml809QYshcRvROQsqquTTyuFzPutvvxQegNWxdLCDiTK1qfuoiNd8EFfcIWK8b4dVd+tQP/97YoWUkdkyn4thsvuoNLMHWKmy4RjXWaVBuvBtiBrrtKHuOol0udqtJNK15KUf64byXR25QzA7TghMlaMPASdKKAj5Q0dpyctF2wO8gDwoDyxZbMH3lqS+aoHr5vncrzqvkSm1/GUJymp1EF3I8jPppvYBSuwMeU9huBTjfNbd89cVfBWJSyNHno9IXtBPWylU2o3VCf2O/S5DbTkwISE4JRskj4LWGcFccT+B2rTfdU55p34WPMLecbFo1NM92ldksWqOqVhQBZsaow/c3xuW/OFOMKsQ66TL5RZVPisXIrj4pXIfTUfhAHUAAAACOlaaLZxjpMJHyhFFbB8AMs3rrXTZWmGg8HYpUikm33d6Sk0cLGrSyur9t8cJwEggkLZQxaapzqI9VehPQCy57</CipherValue>
</CipherData>
</EncryptedData>
</connectionStrings>
</configuration>
No comments:
Post a Comment