Ejemplo n.º 1
0
        private void btn身份认证_Click(object sender, EventArgs e)
        {
            Protocol645 p645 = new Protocol645();

            Esam645Service.EsamOptionClient ESAMproxy = new Esam645Service.EsamOptionClient();//要操作时才new
            string meterNum = "000000000000";

            if (p645.ReadData("04000402", out meterNum))
            {
                tbDiv.Text = "0000" + meterNum;
            }
            else
            {
                MessageBox.Show("读表号出错!");
            }
            Functions.Delay(100);
            int flag = 0;//公钥为0

            if (rbFlagPri.Checked)
            {
                flag = 1;                   //私钥为1
            }
            try
            {
                tbRand.Text   = ESAMproxy.Meter_Formal_IdentityAuthentication(flag, tbDiv.Text).OutRand;   //取随机数
                tbEndata.Text = ESAMproxy.Meter_Formal_IdentityAuthentication(flag, tbDiv.Text).OutEndata; //取密文
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            Functions.Delay(100);
            string result = null;

            if (p645.SecurityAuthentication("070000FF", tbDiv.Text + tbRand.Text + tbEndata.Text, out result))
            {
                tbEsamNo.Text = result.Substring(0, 16);
                tbRand2.Text  = result.Substring(16);
            }
            else//身份认证经常不成功,试多一次又好了,什么鬼。。。那我就试多一次吧。。。
            if (p645.SecurityAuthentication("070000FF", tbDiv.Text + tbRand.Text + tbEndata.Text, out result))
            {
                tbEsamNo.Text = result.Substring(0, 16);
                tbRand2.Text  = result.Substring(16);
            }
            else
            {
                MessageBox.Show("身份认证失败!");
            }
            ESAMproxy.Close();//每次操作完都要关掉!!!真讨厌,老贺你能不能做成自动关掉的啊。。
        }
Ejemplo n.º 2
0
        private void btn身份认证失效_Click(object sender, EventArgs e)
        {
            Protocol645 p645 = new Protocol645();

            tbRegisterFal.Clear();
            Functions.Delay(100);
            string result = null;

            if (p645.SecurityAuthentication("070002FF", "", out result))
            {
                tbRegisterFal.AppendText("身份认证已失效!" + "\r\n");
                tbRegisterFal.AppendText("客户编号:" + result.Substring(24) + "\r\n");
                tbRegisterFal.AppendText("剩余金额(ESAM内):" + result.Substring(16, 8) + "\r\n");
                tbRegisterFal.AppendText("购电次数(ESAM内):" + result.Substring(8, 8) + "\r\n");
                tbRegisterFal.AppendText("密钥状态:" + result.Substring(0, 8) + "\r\n");
            }
            else
            {
                MessageBox.Show("身份认证失效错误");
            }
        }
Ejemplo n.º 3
0
 private void btn设认证时效_Click(object sender, EventArgs e)
 {
     if (Functions.IsNum(tbRenzhengshixiao.Text) && tbRenzhengshixiao.Text.Length == 4)
     {
         if (tbRand2.Text != "" && tbEsamNo.Text != "")
         {
             Esam645Service.EsamOptionClient ESAMproxy = new Esam645Service.EsamOptionClient();//要操作时才new
             try
             {
                 string      putApdu = "04D6822B0E";
                 string      macStr  = ESAMproxy.Meter_Formal_ParameterUpdate(0, tbRand2.Text, tbDiv.Text, putApdu, tbRenzhengshixiao.Text).MAC;
                 string      putData = macStr + tbRenzhengshixiao.Text;
                 string      ret     = null;
                 Protocol645 p645    = new Protocol645();
                 p645.SecurityAuthentication("070001FF", putData, out ret);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
                 return;
             }
             finally
             {
                 ESAMproxy.Close();
             }
         }
         else
         {
             MessageBox.Show("请先身份认证!");
         }
     }
     else
     {
         MessageBox.Show("请输入4位数字时效!");
     }
 }