Created
April 12, 2019 15:24
-
-
Save shareefhiasat/b52130c47a5315d8fca3eb2e6e93f104 to your computer and use it in GitHub Desktop.
Connection String Encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.ComponentModel; | |
using System.Data; | |
using System.Drawing; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Windows.Forms; | |
using System.Diagnostics; | |
using System.IO; | |
namespace EncryptionUtility | |
{ | |
public partial class Form1 : Form | |
{ | |
public Form1() | |
{ | |
InitializeComponent(); | |
} | |
private void button1_Click(object sender, EventArgs e) | |
{ | |
try | |
{ | |
int size = -1; | |
openFileDialog1.Filter = "Configuration File (.config)|*.config"; | |
openFileDialog1.Multiselect = false; | |
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. | |
if (result == DialogResult.OK) // Test result. | |
{ | |
string file = openFileDialog1.FileName; | |
GenerateFile(Path.GetDirectoryName(file)); | |
} | |
}catch (Exception ex) | |
{ | |
label1.Text = ex.ToString(); | |
} | |
} | |
private void GenerateFile(string connectionStringPath) | |
{ | |
string fileName = @"C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe"; | |
if (8 == IntPtr.Size | |
|| (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")))) | |
fileName = @"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe"; | |
string arguments = $"-pef \"connectionStrings\" \"{connectionStringPath}\""; | |
using (Process process = new Process()) | |
{ | |
process.EnableRaisingEvents = true; | |
process.StartInfo = new ProcessStartInfo | |
{ | |
FileName = fileName, | |
Arguments = arguments, | |
UseShellExecute = false, | |
RedirectStandardOutput = true, | |
RedirectStandardError = true, | |
CreateNoWindow = true | |
}; | |
process.Start(); | |
string output = process.StandardOutput.ReadToEnd(); | |
label1.Text = output; | |
//MessageBox.Show(output); | |
string err = process.StandardError.ReadToEnd(); | |
//MessageBox.Show(err); | |
process.WaitForExit(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment