Beispiel #1
0
        /// <summary>
        /// 经过des加密后、写入秘钥(用户名pri.txt)
        /// </summary>
        /// <param name="userD">秘钥</param>
        /// <param name="file">要写入的文件名</param>
        public void WriterKey(BigInteger userD, string file)
        {
            try
            {
                string     path = file;
                FileStream Ali;
                file       fi  = new file();
                desKey     des = new desKey();

                Ali = new FileStream(path, FileMode.Create, FileAccess.Write); //创建写入文件
                StreamWriter sr = new StreamWriter(Ali);
                string       ss = des.Encrypt(userD.ToString(16), "abcdefgh"); //des加密,"abcdefgh"为加密随机数

                sr.WriteLine(ss);                                              //写入文件


                sr.Close();
            }
            catch (Exception ee)
            {
                MessageBox.Show("ecc类异常 1\r\n" + ee.ToString());
            }
        }
Beispiel #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     #region 检测IP是否合法并将合法IP端口信息写入ipMsg.txt文件中
     IPAddress myIP;
     string    ip   = textBox1.Text.Trim() + "." + textBox2.Text.Trim() + "." + textBox3.Text.Trim() + "." + textBox4.Text.Trim();
     string    port = textBox5.Text.Trim();
     if (IPAddress.TryParse(ip, out myIP))
     {
         MessageBox.Show("当前IP为:" + ip + "\n\n" + "端口号为:" + port, "重置IP成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
         this.Close();
         string ipStr = textBox1.Text.Trim() + "." + textBox2.Text.Trim() + "." + textBox3.Text.Trim() + "." + textBox4.Text.Trim() + ":" + textBox5.Text.Trim();
         //自己写的文件读写类
         file wd = new file();
         //writer()函数第一个参数为文件名字、第二个为要写如文件的名字
         // wd.writer("..\\..\\..\\..\\ipMsg.txt", ipStr);
         wd.writer("ipMsg.txt", ipStr);
     }
     else
     {
         MessageBox.Show("IP非法!请重新设置");
     }
     #endregion
 }
Beispiel #3
0
        private void setIP_Load(object sender, EventArgs e)
        {
            #region IP和端口信息的读取和档文件ipMsg.txt不存在时的初始化
            //读取ipMsg.txt中的IP配置
            try
            {
                string a1, a2, a3, a4, port;
                a1 = a2 = a3 = a4 = port = "";
                int b1, b2, b3, b4, i;
                b1 = b2 = b3 = b4 = i = 0;
                //自己写的文件读写类
                file re = new file();
                //reader()为返回从指定文件都出来的数据,其参数为文件路径
                //string read = re.reader("..\\..\\..\\..\\ipMsg.txt");
                //
                string read   = re.reader("ipMsg.txt");
                int    length = read.Length;

                while (true)
                {
                    if (b1 == 0 && b2 == 0 && b3 == 0)
                    {
                        if (read[i].ToString() == ".")
                        {
                            b1 = 1;
                            i++;
                        }
                        else
                        {
                            a1 += read[i];
                        }
                    }
                    if (b1 == 1 && b2 == 0 && b3 == 0)
                    {
                        if (read[i].ToString() == ".")
                        {
                            b2 = 1;
                            i++;
                        }
                        else
                        {
                            a2 += read[i];
                        }
                    }
                    if (b1 == 1 && b2 == 1 && b3 == 0)
                    {
                        if (read[i].ToString() == ".")
                        {
                            b3 = 1;
                            i++;
                        }
                        else
                        {
                            a3 += read[i];
                        }
                    }
                    if (b1 == 1 && b2 == 1 && b3 == 1 && b4 == 0)
                    {
                        if (read[i].ToString() == ":")
                        {
                            b4 = 1;
                            i++;
                        }
                        else
                        {
                            a4 += read[i];
                        }
                    }
                    if (b1 == 1 && b2 == 1 && b3 == 1 && b4 == 1)
                    {
                        if (i == length)
                        {
                            break;
                        }
                        else
                        {
                            port += read[i];
                        }
                    }
                    i++;
                }
                textBox1.Text = a1;
                textBox2.Text = a2;
                textBox3.Text = a3;
                textBox4.Text = a4;
                textBox5.Text = port;
            }
            //当文件不存在的时候新建初并始化ipMsg.txt
            catch
            {
                string ipStr = textBox1.Text.Trim() + "." + textBox2.Text.Trim() + "." + textBox3.Text.Trim() + "." + textBox4.Text.Trim() + ":" + textBox5.Text.Trim();
                //自己写的文件读写类
                file wd = new file();
                //writer()函数第一个参数为文件名字、第二个为要写如文件的名字
                wd.writer("ipMsg.txt", ipStr);
                //wd.writer("..\\..\\..\\..\\ipMsg.txt", ipStr);
            }
            #endregion
        }
Beispiel #4
0
        private void kgcKey_Load(object sender, EventArgs e)
        {
            file file = new file();

            textBox1.Text = des.Decrypt(file.reader("pk.txt"), "abcdefgh");
        }