private void btnCreate_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtRegInfo.Text.Trim())) { MessageBox.Show(@"注册信息不能为空!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string filename = ""; SystemRegInfo info = new SystemRegInfo(); info.IsAuthorized = NicholasEncrypt.EncryptUTF8String("HasAuthorized", GetSystemInfo.EncrytionKey); info.RegKey = txtRegInfo.Text.Trim(); info.StartDate = dtpStart.Value.ToString(); info.EndDate = dtpEnd.Value.ToString(); SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = @"授权文件|*.leo"; sfd.FileName = DateTime.Now.ToString("yyyyMMddhhmmss") + "系统授权"; sfd.RestoreDirectory = true; sfd.CheckPathExists = true; if (sfd.ShowDialog() == DialogResult.OK) { filename = sfd.FileName; XmlHelper.CreateRegInfoXml(filename, info); //PiEncryptHelper.EncFile(filename); MessageBox.Show(@"生成成功!"); } }
private void button4_Click(object sender, EventArgs e) { string t = textBox2.Text.Trim(); string r = NicholasEncrypt.EncryptUTF8String(t, GetSystemInfo.EncrytionKey); textBox3.Text = r; label2.Text = NicholasEncrypt.DecryptUTF8String(r, GetSystemInfo.EncrytionKey); //label3.Text = NicholasEncrypt.EncryptString(CheckRegInfo.LocalKey, GetSystemInfo.EncrytionKey); }
private void btnRegister_Click(object sender, EventArgs e) { try { string path = txtRegFile.Text.Trim(); PiEncryptHelper.DecFile(path); SystemRegInfo regInfo = XmlHelper.GetSystemRegInfo(path, "Software"); PiEncryptHelper.EncFile(path); if (regInfo == null) { MessageBox.Show(@"读取授权文件失败!", @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error); //DialogResult = DialogResult.OK; RegSuccess = false; return; } if (regInfo.RegKey != CheckRegInfo.AesLocalKey) { MessageBox.Show(@"该授权文件无法在该电脑上激活!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //DialogResult = DialogResult.OK; RegSuccess = false; return; } DateTime endTime = Convert.ToDateTime(regInfo.EndDate); if (DateTime.Compare(endTime, DateTime.Now) < 0) { MessageBox.Show(@"该授权文件已过期,请重新激活!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //DialogResult = DialogResult.OK; RegSuccess = false; return; } DateTime startTime = Convert.ToDateTime(regInfo.StartDate); if (DateTime.Compare(startTime, DateTime.Now) > 0) { MessageBox.Show(@"检测到电脑系统时间不是北京时间,请将电脑时间调整到当前北京时间!", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //DialogResult = DialogResult.OK; RegSuccess = false; return; } if (File.Exists(_regPath)) { PiEncryptHelper.DecFile(_regPath); XmlHelper.Update(_regPath, regInfo); } else { XmlHelper.CreateRegInfoXml(_regPath, regInfo); } RegisterClass.UpdateSubKey("Nicholas", NicholasEncrypt.EncryptUTF8String("0", GetSystemInfo.EncrytionKey)); RegisterClass.UpdateSubKey("Leo", NicholasEncrypt.EncryptUTF8String("YES", GetSystemInfo.EncrytionKey)); RegisterClass.UpdateSubKey("NicholasLeo", NicholasEncrypt.EncryptUTF8String("Due", GetSystemInfo.EncrytionKey)); RegSuccess = true; PiEncryptHelper.EncFile(_regPath); MessageBox.Show(@"系统成功激活!"); DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private string SelfDecrypt(string value) { return(NicholasEncrypt.DecryptUTF8String(value, NicholasLeoKey.MyKey)); }