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("修改失败"); } }
private void initsafetab() { SafePart.src.Message message = new SafePart.src.Message(); string currentlevel = message.Level; ClientAES clientaes = new ClientAES(); byte[] level1 = clientaes.Level1; byte[] level2 = clientaes.Level2; string strlevel1 = Encoding.ASCII.GetString(level1); string strlevel2 = Encoding.ASCII.GetString(level2); levelbtcurrent.Text = currentlevel; levelcbask.Items.Clear(); levelcbask.Items.Add("1"); levelcbask.Items.Add("2"); leveltbone.Text = strlevel1; leveltbtwo.Text = strlevel2; }