Beispiel #1
0
        private void levelbtask_Click(object sender, EventArgs e)
        {
            SafePart.src.Message message = new SafePart.src.Message();
            string type = "3\n";
            string id   = message.Number + '\n';

            type += id;
            ClientAES aes    = new ClientAES();
            string    level  = levelcbask.Text;
            int       length = type.Length;

            byte[] buffer = new byte[2048];
            byte[] en     = new byte[2048];
            Array.Copy(Encoding.ASCII.GetBytes(type), 0, buffer, 0, length);
            byte[] bufferlevel = Encoding.ASCII.GetBytes(level + '\n');
            byte[] bufferkey;
            if (level.Equals("1"))
            {
                bufferkey = aes.Level1;
            }
            else
            {
                bufferkey = aes.Level2;
            }
            int pos = length;

            Array.Copy(bufferlevel, 0, buffer, pos, bufferlevel.Length);
            pos += bufferlevel.Length;
            Array.Copy(bufferkey, 0, buffer, pos, bufferkey.Length);
            pos        += bufferkey.Length;
            buffer[pos] = (byte)'\n';
            for (int i = pos + 1; i < 2048; i++)
            {
                buffer[i] = (byte)'*';
            }
            Array.Copy(buffer, en, 2048);
            ServerRSA rsa = new ServerRSA();

            for (int i = 0; i < 2048 / 128 - 1; i++)
            {
                byte[] preen = new byte[128];
                byte[] prede = new byte[128];
                Array.Copy(buffer, i * 128 + type.Length, preen, 0, 128);
                prede = EnDeRSA.Enwithpublickey(preen, rsa.Publickey);
                Array.Copy(prede, 0, en, i * 128 + type.Length, 128);
            }
            if (Common.sendbytes(en, ConfigurationSettings.AppSettings["serverport"]))
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }
Beispiel #2
0
        private void messagebtmodify_Click(object sender, EventArgs e)
        {
            SafePart.src.Message mes = new SafePart.src.Message();
            mes.Messagevalue = messagetbcheck.Text;
            mes.Level        = messagetblevel.Text;
            mes.Address      = messagetbaddress.Text;
            mes.Email        = messagetbemail.Text;
            mes.Number       = messagetbnumber.Text;
            string title = "2\n";
            string idnum = mes.Number + "\n";

            title += idnum;
            int    tiltelen = title.Length;
            string sendto   = mes.getmessage();

            byte[]    buffer = Encoding.ASCII.GetBytes(sendto);
            ServerRSA rsa    = new ServerRSA();

            //   buffer = EnDeRSA.Enwithpublickey(buffer, rsa.Publickey);
            byte[] sign = new byte[2048];
            //  sign = Encoding.ASCII.GetBytes(title);
            Array.Copy(Encoding.ASCII.GetBytes(title), sign, title.Length);
            int i = 0;

            for (i = 0; i < buffer.Length; i++)
            {
                sign[tiltelen + i] = buffer[i];
            }
            i += title.Length;
            for (; i < 2048; i++)
            {
                sign[i] = (byte)'*';
            }
            byte[] en = new byte[2048];
            en = sign;
            for (i = 0; i < 2048 / 128 - 1; i++)
            {
                byte [] preen = new byte[128];
                byte [] prede = new byte[128];
                Array.Copy(sign, i * 128 + title.Length, preen, 0, 128);
                prede = EnDeRSA.Enwithpublickey(preen, rsa.Publickey);
                Array.Copy(prede, 0, en, i * 128 + title.Length, 128);
            }
            if (Common.sendbytes(en, ConfigurationSettings.AppSettings["serverport"]))
            {
                MessageBox.Show("修改成功");
            }
            else
            {
                MessageBox.Show("修改失败");
            }
        }