using Microsoft.Win32;
//写入数据
public void Write(string key, string data)
{
try
{
data = Encrypt(data);
RegistryKey regkey = Registry.LocalMachine.CreateSubKey(this.path);
regkey.SetValue(key, data);
Registry.LocalMachine.Flush();
}
catch (Exception ex)
{
Trace.WriteLine(ex.StackTrace);
}
}
//读出数据
public string Read(string key)
{
try
{
RegistryKey regkey = Registry.LocalMachine.OpenSubKey(this.path);
string data = (string)regkey.GetValue(key);
return Decrypt(data);
}
catch(Exception ex)
{
Trace.WriteLine(ex.StackTrace);
return string.Empty;
}
}
//对用户输入的信息转换
private static string Encrypt(string plainText)
{
byte[] clearBytes = ASCIIEncoding.ASCII.GetBytes(plainText);
PasswordDeriveBytes pdb = new PasswordDeriveBytes(ThisToken,
new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
//调用写入方法
public void WriteBug()
{
RegistryTools tool = new RegistryTools(@"Software/BFSL/CMMWebSite/BugReport");
tool.Write("Path",System.Web.HttpUtility.UrlEncode( this.txt服务路径.Text));
tool.Write("UserName", System.Web.HttpUtility.UrlEncode(this.txt用户名称.Text));
tool.Write("ProjectName", System.Web.HttpUtility.UrlEncode(this.txt项目名称.Text));
}
// 调用读取方法
private void LoadConfig()
{
private string userName;
private string projectName;
RegistryTools tool = new RegistryTools(@"Software/BFSL/CMMWebSite/BugReport");
this.url = System.Web.HttpUtility.UrlDecode(tool.Read("Path"));
this.userName= System.Web.HttpUtility.UrlDecode(tool.Read("UserName"));
this.projectName = System.Web.HttpUtility.UrlDecode(tool.Read("ProjectName"));
}