示例#1
0
        private void txtReadUKey_Click(object sender, EventArgs e)
        {
            NETCAPKIv4 oNETCAPKIv4 = new NETCAPKIv4();
            ///// 获取用户证书
            string CertUID  = "";
            string key_DW   = "";
            string key_Name = "";
            string key_Sfzh = "";

            #region 获取ca信息

            try
            {
                try
                {
                    X509Certificate oCert = NETCAPKIv4.getX509Certificate(
                        NETCAPKIv4.SECUINTER_CURRENT_USER_STORE, NETCAPKIv4.SECUINTER_MY_STORE,
                        NETCAPKIv4.SECUINTER_CERTTYPE_SIGN,
                        NETCAPKIv4.SECUINTER_NETCA_YES);
                    if (oCert == null)
                    {
                        MessageBox.Show("未找到证书");
                        return;
                    }
                    ////用户证书绑定值
                    CertUID = (NETCAPKIv4.getX509CertificateInfo(oCert, 9));
                    ////单位
                    key_DW = (NETCAPKIv4.getX509CertificateInfo(oCert, 13));
                    ////用户名称
                    key_Name = (NETCAPKIv4.getX509CertificateInfo(oCert, 12));
                    ////证书序列号
                    //CertID=(oNETCAPKIv4.GetCertInfo(Cert, 2));
                    ////证件号
                    key_Sfzh = (NETCAPKIv4.getX509CertificateInfo(oCert, 36));

                    txtCaId.Text   = CertUID;
                    txtCaName.Text = key_Name;
                }
                catch (Exception ee1)
                {
                    if (ee1.Message == "证书选择失败")
                    {
                        MessageBox.Show("证书选择失败,请确认Key盘是否插入");
                    }
                    else
                    {
                        MessageBox.Show(ee1.Message);
                    }
                    return;
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("程序初始化失败");
                return;
            }

            #endregion
        }
示例#2
0
        private string Login()
        {
            NETCAPKIv4 oNETCAPKIv4 = new NETCAPKIv4();
            ///// 获取用户证书
            string CertUID  = "";
            string key_DW   = "";
            string key_Name = "";
            string key_Sfzh = "";

            try
            {
                try
                {
                    SecuInter.X509Certificate oCert = NETCAPKIv4.getX509Certificate(
                        NETCAPKIv4.SECUINTER_CURRENT_USER_STORE, NETCAPKIv4.SECUINTER_MY_STORE,
                        NETCAPKIv4.SECUINTER_CERTTYPE_SIGN,
                        NETCAPKIv4.SECUINTER_NETCA_YES);
                    if (oCert == null)
                    {
                        MessageBox.Show("未找到证书");
                        return("0");
                    }
                    ////用户证书绑定值
                    CertUID = (NETCAPKIv4.getX509CertificateInfo(oCert, 9));
                    ////单位
                    key_DW = (NETCAPKIv4.getX509CertificateInfo(oCert, 13));
                    ////用户名称
                    key_Name = (NETCAPKIv4.getX509CertificateInfo(oCert, 12));
                    ////证书序列号
                    //CertID=(oNETCAPKIv4.GetCertInfo(Cert, 2));
                    ////证件号
                    key_Sfzh = (NETCAPKIv4.getX509CertificateInfo(oCert, 36));
                }
                catch (Exception ee1)
                {
                    if (ee1.Message == "证书选择失败")
                    {
                        MessageBox.Show("证书选择失败,请确认Key盘是否插入");
                    }
                    else
                    {
                        MessageBox.Show(ee1.Message);
                    }
                    return("0");
                }
            }
            catch (Exception ee)
            {
                MessageBox.Show("程序初始化失败");
                return("0");
            }


            /// 验证用户名
            DataTable Dt_yh = GetYHXX(CertUID);

            if (Dt_yh.Rows.Count > 0)
            {
                if (f.ReadString("CA", "yzsfzh", "0").Replace("\0", "").Trim() == "1")
                {
                    if (Dt_yh.Rows[0]["F_SFZH"].ToString().Trim() != key_Sfzh)
                    {
                        MessageBox.Show("用户身份证号不匹配,登陆失败!");
                        return("0");
                    }
                }
                if (f.ReadString("CA", "yzxm", "0").Replace("\0", "").Trim() == "1")
                {
                    if (key_Name != Dt_yh.Rows[0]["F_YHMC"].ToString().Trim())
                    {
                        MessageBox.Show("用户姓名不匹配,登陆失败");
                        return("0");
                    }
                }

                if (f.ReadString("CA", "yzyhbh", "0").Replace("\0", "").Trim() == "1")
                {
                    //获取OID值中的证件信息
                    string str1 = CertUID.Substring(CertUID.IndexOf("@") + 8);

                    //解码
                    byte[] bs     = NETCAPKIv4.base64Decode(str1);
                    string Key_gh = Encoding.Default.GetString(bs);

                    if (Dt_yh.Rows[0]["F_YHBH"].ToString().Trim() != Key_gh)
                    {
                        MessageBox.Show("用户工号与KEY中工号不一致,验证失败!");
                        return("0");
                    }
                }

                return(Dt_yh.Rows[0]["F_YHM"].ToString().Trim() + "^" + Dt_yh.Rows[0]["F_YHMM"].ToString().Trim());
            }
            else
            {
                MessageBox.Show("未查询到此用户信息或此用户Key未绑定");
                return("0");
            }
        }