Beispiel #1
0
        protected void Application_Start(object sender, EventArgs e)
        {
            CPublic.AppPath = Server.MapPath(@"\");
            CPublic.LogPath = CPublic.AppPath + "Log\\";
            CPublic.AuthUpdate();
            //int nRet = CPublic.Init();
            //if (nRet != 0)
            //{
            //    CPublic.WriteLog("Web Service 初始化失败,nRet=" + nRet.ToString());
            //}
            int nRet = TPE_Class.TPE_GetNetState();

            if (nRet != 3)
            {
                TPE_Class.TPE_StartTPE();
            }
            for (int i = 0; i < 20; i++)
            {
                nRet = TPE_Class.TPE_GetNetState();
                if (nRet == 3)
                {
                    nRet = TPE_Class.TPE_GetLocalNode();
                    CPublic.LocalNode = nRet.ToString();
                    CPublic.WriteLog("TPE LocalNode " + nRet);
                    CPublic.WriteLog("TPE OK " + i);
                    break;
                }
                Thread.Sleep(1000);
            }
            CPublic.WriteLog("Application_Start");
        }
Beispiel #2
0
 public string MD5(string strPlain)
 {
     try
     {
         CMD5   md5        = new CMD5();
         byte[] plainArray = Encoding.UTF8.GetBytes(strPlain);
         byte[] mac        = md5.MAC(plainArray);
         return(Convert.ToBase64String(mac));
     }
     catch (Exception e)
     {
         CPublic.WriteLog("MD5 签名过程异常:" + e.Message);
         return(null);
     }
 }
Beispiel #3
0
        public int TokenVaildCheck(string User, string param, string sha, string DoingLog)
        {
            // -1: 需更新令牌
            // 0: 验证正确
            // 1: 验证失败
            // 2: 令牌无效
            // 3: 信息错误

/*            CPublic.WriteLog ("提供的 SHA:" + sha.ToUpper () + ",计算的 SHA:" + SHA1 (param + "$" + TokenAuth).ToUpper () + ",内容:" + param + "$" + TokenAuth);
 *          if (!string.IsNullOrEmpty (oldTokenAuth)) {
 *              CPublic.WriteLog ("提供的 SHA:" + sha.ToUpper () + ",计算的 SHA:" + SHA1 (param + "$" + oldTokenAuth).ToUpper () + ",内容:" + param + "$" + oldTokenAuth);
 *              CPublic.WriteLog ("检测到存在旧密钥");
 *          } else { CPublic.WriteLog ("未检测到存在旧密钥"); }*/
            if (TokenUser == User)
            {
                if (Usable())
                {
                    if (sha.ToUpper().Equals(SHA1(param + "$" + TokenAuth).ToUpper()))
                    {
                        Update();
                        CPublic.WriteLog(TokenUser + ": " + DoingLog);
                        return(0);
                    }
                    else if (!string.IsNullOrEmpty(oldTokenAuth) && oldTokenLifetime > DateTime.Now)
                    {
                        if (sha.ToUpper().Equals(SHA1(param + "$" + oldTokenAuth).ToUpper()))
                        {
                            CPublic.WriteLog(TokenUser + ": " + DoingLog);
                            return(-1);
                        }
                        return(2);
                    }
                    return(1);
                }
                else if (Replaceable())
                {
                    if (sha.ToUpper().Equals(SHA1(param + "$" + TokenAuth).ToUpper()))
                    {
                        CPublic.WriteLog(TokenUser + ": " + DoingLog);
                        return(-1);
                    }
                    return(1);
                }
                return(2);
            }
            return(3);
        }
Beispiel #4
0
 public string DesEncrypt(string strPlain, string strKey)
 {
     try
     {
         CDES   des         = new CDES();
         byte[] key         = Encoding.UTF8.GetBytes(strKey);
         byte[] plainArray  = Encoding.UTF8.GetBytes(strPlain);
         byte[] cipherArray = des.Encrypt(plainArray, 0, plainArray.Length, key);
         //return Encoding.UTF8.GetString(cipherArray);
         return(Convert.ToBase64String(cipherArray));
     }
     catch (Exception e)
     {
         CPublic.WriteLog("DES 加密过程异常:" + e.Message);
         return(null);
     }
 }
Beispiel #5
0
 public string DesDecrypt(string strCipher, string strKey)
 {
     try
     {
         CDES   des         = new CDES();
         byte[] key         = Encoding.UTF8.GetBytes(strKey);
         byte[] cipherArray = Convert.FromBase64String(strCipher);
         //byte[] cipherArray = Encoding.UTF8.GetBytes(strCipher);
         byte[] plainArray = des.Decrypt(cipherArray, 0, cipherArray.Length, key);
         return(Encoding.UTF8.GetString(plainArray));
     }
     catch (Exception e)
     {
         CPublic.WriteLog("DES 解密过程异常:" + e.Message);
         return(null);
     }
 }
Beispiel #6
0
        //public static SqlConnection conn = new SqlConnection();

        //@"Data Source=" + IP + ";Initial Catalog=SMS;User ID=" + UserName + ";Password="******"DBConfig.cfg"))
                {
                    using (FileStream fs = new FileStream(AppPath + "DBConfig.cfg", FileMode.Open, FileAccess.Read, FileShare.None))
                    {
                        byte[] buf      = new byte[2048];
                        int    nReadNum = fs.Read(buf, 0, 2048);
                        if (nReadNum != 2048)
                        {
                            CPublic.WriteLog("读取数据库连年配置文件失败,长度不足.");
                        }
                        else
                        {
                            EncryptHelper eh = new EncryptHelper();

                            int len = BitConverter.ToInt32(buf, 0);
                            ConnString = eh.DesDecrypt(Encoding.GetEncoding("gb2312").GetString(buf, 4, len), "synjones");

                            len = BitConverter.ToInt32(buf, 1024);
                            string ConOperKey = eh.DesDecrypt(Encoding.GetEncoding("gb2312").GetString(buf, 1028, len), "synjones");
                        }
                    }
                }
                else
                {
                    CPublic.WriteLog("数据库连接配置文件不存在,请使用工具生,并放在目录:" + AppPath);
                }

                return(0);
            }
            catch (Exception e)
            {
                CPublic.WriteLog("初始化异常:" + e.Message);
                return(-1);
            }
        }
Beispiel #7
0
 protected void Application_End(object sender, EventArgs e)
 {
     TPE_Class.TPE_StopTPE();
     CPublic.WriteLog("Application_End");
 }
Beispiel #8
0
 protected void Application_Error(object sender, EventArgs e)
 {
     CPublic.WriteLog("Application_Error");
 }
Beispiel #9
0
 protected void Application_AuthenticateRequest(object sender, EventArgs e)
 {
     CPublic.WriteLog("Application_AuthenticateRequest");
 }
Beispiel #10
0
 protected void Session_Start(object sender, EventArgs e)
 {
     CPublic.WriteLog("Session_Start");
 }