Example #1
0
 /// <summary>
 /// P7签名验证
 /// </summary>
 /// <param name="encryptData">密文</param>
 /// <returns>0 验证成功</returns>
 public int P7Verify(string encryptData)
 {
     return(vstkClientPro.SOF_VerifySignedDataByP7(encryptData));
 }
Example #2
0
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userID">用户编号</param>
        /// <param name="strcerId">证书ID</param>
        /// <param name="strpwd">密码</param>
        /// <returns></returns>
        public bool LoginUser(string userID, string strpwd, out string strmsg)
        {
            try
            {
                strmsg = "";
                if (!InitCa(out strmsg))
                {
                    return(false);
                }
                InitCaConnection(out strmsg);
                if (!"".Equals(strmsg))
                {
                    return(false);
                }
                //UKEY 密码验证
                int usbLogin = medicalTK.SOF_Login(cerlst[0], strpwd);
                //验证通过
                if (usbLogin == 0)
                {
                    ////获取Base64编码的证书字符串
                    //certBase64 = medicalTK.SOF_ExportUserCert(cerlst[0]);
                    //获取随机码
                    string random = GetRandom();
                    //对随机码进行P7签名
                    string encryptData = P7Sign(cerlst[0], random);
                    if ("".Equals(encryptData))
                    {
                        strmsg = "P7签名出错,错误码:" + medicalTK.GetLastError();
                        return(false);
                    }
                    int iRet;
                    //服务端验证P7签名数据
                    iRet = vstkClientPro.SOF_VerifySignedDataByP7(encryptData);
                    if (iRet != 0)
                    {
                        strmsg = "P7验签失败,返回值:" + medicalTK.GetLastError();
                        return(false);
                    }
                    //P7验证通过 进一步验证随机数是否正确
                    string randomServer = GetDataInfoByP7(encryptData, 1);
                    //随机数验证通过
                    if (random.Equals(randomServer))
                    {
                        //验证通过,获取工号
                        _userId = GetCertInfoByOId(certBase64, "2.4.16.11.7.3");

                        MessageBox.Show(_userId);
                    }
                    else if ("".Equals(randomServer))
                    {
                        strmsg = "获取原文信息失败,返回值:" + medicalTK.GetLastError();
                        return(false);
                    }
                    else if (!random.Equals(randomServer))
                    {
                        strmsg = "解析原文不一致,解析值:" + randomServer;
                        return(false);
                    }
                    else
                    {
                        strmsg = "未知错误,错误码:" + medicalTK.GetLastError();
                        return(false);
                    }
                }
                else
                {
                    strmsg = "错误码:" + medicalTK.GetLastError();
                    return(false);
                }
                return(true);
            }
            catch (Exception err)
            {
                strmsg = err.Message;
                return(false);
            }
        }