/// <summary>
        /// 保存授权文件
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool SaveSystemAuthorization(SeatManage.ClassModel.SystemAuthorization model)
        {
            if (model == null)
            {
                return(false);
            }
            string       filePath = string.Format(@"{0}SystemAuthorizedkeys", AppDomain.CurrentDomain.BaseDirectory);
            StreamWriter file     = new StreamWriter(filePath, false, Encoding.ASCII);

            try
            {
                string strJson    = SeatManage.SeatManageComm.JSONSerializer.Serialize(model);
                string ciphertext = SeatManage.SeatManageComm.AESAlgorithm.AESEncrypt(strJson);
                file.WriteLine(ciphertext);
                return(true);
            }
            catch
            {
                throw;
            }
            finally
            {
                file.Flush();
            }
        }
        /// <summary>
        /// 获取授权文件
        /// </summary>
        /// <returns></returns>
        public SeatManage.ClassModel.SystemAuthorization GetSystemAuthorization()
        {
            string filePath = string.Format(@"{0}SystemAuthorizedkeys", AppDomain.CurrentDomain.BaseDirectory);

            SeatManage.ClassModel.SystemAuthorization model = null;
            string encryptionContext = "";

            if (File.Exists(filePath))
            {
                encryptionContext = File.ReadAllText(filePath, Encoding.ASCII);
            }
            else
            {
                throw new Exception("未找到授权文件。");
            }
            try
            {
                model = SeatManage.SeatManageComm.JSONSerializer.Deserialize <SeatManage.ClassModel.SystemAuthorization>(SeatManage.SeatManageComm.AESAlgorithm.AESDecrypt(encryptionContext));
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(model);
        }
Example #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //SystemAuthorizedkeys
            string sPath = string.Format(@"{0}SystemAuthorized\", AppDomain.CurrentDomain.BaseDirectory);

            if (!Directory.Exists(sPath))
            {
                Directory.CreateDirectory(sPath);
            }
            SeatManage.ClassModel.SystemAuthorization model = new SeatManage.ClassModel.SystemAuthorization();
            model.SchoolNum       = textBox1.Text;
            model.SeatClientCount = int.Parse(textBox2.Text);
            for (int i = 0; i < model.SeatClientCount; i++)
            {
                model.SeatClientList.Add(model.SchoolNum + (i + 1).ToString("D2"), DateTime.Now);
            }
            string       filePath = string.Format(@"{0}SystemAuthorizedkeys", sPath);
            StreamWriter file     = new StreamWriter(filePath, false, Encoding.ASCII);

            try
            {
                string strJson    = SeatManage.SeatManageComm.JSONSerializer.Serialize(model);
                string ciphertext = SeatManage.SeatManageComm.AESAlgorithm.AESEncrypt(strJson);
                file.WriteLine(ciphertext);
                MessageBox.Show("生成完成!");
                System.Diagnostics.Process.Start("Explorer.exe", sPath);
            }
            catch
            {
                MessageBox.Show("生成失败!");
            }
            finally
            {
                file.Flush();
            }
        }