コード例 #1
0
        private void button6_Click(object sender, EventArgs e)
        {
            string         file   = string.Empty;
            OpenFileDialog dialog = new OpenFileDialog
            {
                Multiselect = false,//该值确定是否可以选择多个文件
                Title       = "请选择文件夹",
                Filter      = "授权文件(*.licd)|*.licd|所有文件(*.*)|*.*"
            };

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                file = dialog.FileName;
            }
            else
            {
                return;
            }
            List <string> vrList = new List <string>();

            vrList = WriteEncrptyFile.GetInstance().ReadEncrptyFile(file);

            foreach (var indata in vrList)
            {
                if (indata.ToString() != "")
                {
                    int irow = dataGridView1.Rows.Add();
                    dataGridView1.Rows[irow].Cells[3].Value = indata.ToString();
                }
            }
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //从datagrid中生成加密文件
            if (dataGridView1.Rows.Count <= 1)
            {
                textBox3.Text = ("为添加相关门锁数据");
                return;
            }

            try
            {
                //
                string m_value1 = string.Empty;
                string m_value2 = string.Empty;
                string m_value3 = string.Empty;

                WriteEncrptyFile.GetInstance().DeletFile(WriteEncrptyFile.GetInstance().baseDir + "\\" + WriteEncrptyFile.GetInstance().getFileName());

                foreach (DataGridViewRow dgvr in dataGridView1.Rows)
                {
                    if (dgvr.Cells[0].Value != null && dgvr.Cells[1].Value != null && dgvr.Cells[2].Value != null)
                    {
                        m_value1 = dgvr.Cells[0].Value.ToString();
                        m_value2 = dgvr.Cells[1].Value.ToString();
                        m_value3 = dgvr.Cells[2].Value.ToString();
                        //Key
                        string m_inValue   = m_value1 + "," + m_value2 + "," + m_value3;
                        string m_MasterKey = MasterKey.Text.ToString();
                        if (m_MasterKey.Length != 24)
                        {
                            textBox3.Text = ("密钥长度不正确,请输入24位主密钥");
                            return;
                        }
                        var wrIndata = dgvr.Cells[3].Value = Encrypt3Des(m_inValue, m_MasterKey, CipherMode.CBC, "12345678");
                        WriteEncrptyFile.GetInstance().WriteFile(wrIndata.ToString());
                    }
                }
                textBox3.Text = "加密数据完成";
            }
            catch (Exception ex)
            {
                textBox3.Text = "加密数据异常:" + ex.Message;
            }
        }