private void btn_start_Click(object sender, EventArgs e) { if (txt_key.Text.Trim() == "") { MessageBox.Show("请选择验证钥文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); btn_choose.Focus(); return; } if (!File.Exists(txt_key.Text.Trim())) { MessageBox.Show("读取验证钥文件失败,找不到文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } string strKey = File.ReadAllText(txt_key.Text.Trim()); EnDecryption ende = new EnDecryption(); // 解密 ende.Cryptograph = strKey; strKey = ende.RealPwd; char[] separator = { '#' }; string[] splitKey = strKey.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (splitKey.Length != 5) { MessageBox.Show("验证钥文件数据被破坏,解析失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (splitKey[1] != splitKey[4]) { MessageBox.Show("验证钥文件数据被破坏,解析失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (splitKey[0] != identity) { MessageBox.Show("验证钥身份认证失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } DateTime dtKey = new DateTime(); try { dtKey = Convert.ToDateTime(splitKey[2] + " " + splitKey[1]); DateTime dtNow = DateTime.Now; if (dtKey.ToShortDateString() != dtNow.ToShortDateString()) { MessageBox.Show("日期验证失败,验证钥已过期或未生效!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } } catch { MessageBox.Show("验证钥文件数据被破坏,解析失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } int clockSec = 0; switch (splitKey[3]) { case "TENTEST": clockSec = 605; break; case "HALFHOUR": clockSec = 1800; break; case "ONEHOUR": clockSec = 3600; break; case "TWOHOUR": clockSec = 7200; break; case "THREEHOUR": clockSec = 10800; break; default: MessageBox.Show("验证钥类型认证失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } Write2TickFile(dtKey, clockSec); }