示例#1
0
 public string EncryptString(string source, int mode, Encoding encoding)
 {
     return(ServerAESEncryption.EncryptString(source, (EncryptionMode)mode, encoding));
 }
示例#2
0
 public string EncryptString(string source, int mode)
 {
     //return source;
     return(ServerAESEncryption.EncryptString(source, (EncryptionMode)mode, Encoding.ASCII));
 }
示例#3
0
        private void Login()
        {
            try
            {
                if (DatabaseInfo == null)
                {
                    ShowException(string.Format("Fail.\t DatabaseInfo is null"));
                    return;
                }

                string strAccount  = TxtAccount.Text.Trim();
                string strPassword = TxtPassword.Password.Trim();

                if (string.IsNullOrEmpty(strAccount) ||
                    string.IsNullOrEmpty(strPassword))
                {
                    ShowException(string.Format("Account or password empty!"));
                    return;
                }

                SetBusy(true, App.GetLanguageInfo("N008", string.Format("Checking login information, please wait for a moment...")));
                bool             isFail   = true;
                string           strError = string.Empty;
                OperationReturn  optReturn;
                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (s, de) =>
                {
                    try
                    {
                        string strAccountEncrypt = App.EncryptStringM002(strAccount);
                        int    dbType            = DatabaseInfo.TypeID;
                        string strSql;
                        string strConn      = DatabaseInfo.GetConnectionString();
                        string strRentToken = string.Format("00000");
                        switch (dbType)
                        {
                        case 2:
                            strSql = string.Format("SELECT * FROM T_11_005_{0} WHERE C002 = '{1}'",
                                                   strRentToken,
                                                   strAccountEncrypt);
                            optReturn = MssqlOperation.GetDataSet(strConn, strSql);
                            break;

                        case 3:
                            strSql = string.Format("SELECT * FROM T_11_005_{0} WHERE C002 = '{1}'",
                                                   strRentToken,
                                                   strAccountEncrypt);
                            optReturn = OracleOperation.GetDataSet(strConn, strSql);
                            break;

                        default:
                            strError = string.Format("Database type not support.\t{0}", dbType);
                            return;
                        }
                        if (!optReturn.Result)
                        {
                            strError = string.Format("Fail.\t{0}\t{1}", optReturn.Code, optReturn.Message);
                            return;
                        }
                        DataSet objDataSet = optReturn.Data as DataSet;
                        if (objDataSet == null ||
                            objDataSet.Tables.Count <= 0)
                        {
                            strError = string.Format("DataSet is null");
                            return;
                        }
                        if (objDataSet.Tables[0].Rows.Count <= 0)
                        {
                            strError = string.Format("Account not exist.\t{0}", strAccount);
                            return;
                        }
                        DataRow dr       = objDataSet.Tables[0].Rows[0];
                        long    userID   = Convert.ToInt64(dr["C001"]);
                        string  strPass  = dr["C004"].ToString();
                        string  strTemp  = string.Format("{0}{1}", userID, strPassword);
                        byte[]  byteTemp = ServerHashEncryption.EncryptBytes(Encoding.Unicode.GetBytes(strTemp),
                                                                             EncryptionMode.SHA512V00Hex);
                        var aes = ServerAESEncryption.EncryptBytes(byteTemp, EncryptionMode.AES256V02Hex);
                        strTemp = ServerEncryptionUtils.Byte2Hex(aes);
                        if (!strTemp.Equals(strPass))
                        {
                            strError = string.Format("Password error.");
                            return;
                        }
                        IsLogined = true;
                        UserInfo userInfo = new UserInfo();
                        userInfo.UserID   = userID;
                        userInfo.Account  = strAccount;
                        userInfo.Password = strPassword;
                        UserInfo          = userInfo;
                        isFail            = false;
                    }
                    catch (Exception ex)
                    {
                        strError = string.Format("Fail.\t{0}", ex.Message);
                    }
                };
                worker.RunWorkerCompleted += (s, re) =>
                {
                    worker.Dispose();
                    SetBusy(false, string.Empty);

                    if (isFail)
                    {
                        ShowException(strError);
                        return;
                    }
                    DialogResult = true;
                    Close();
                };
                worker.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                ShowException(ex.Message);
            }
        }
示例#4
0
        private OperationReturn ModifyUserPasswordM003(SessionInfo session, List <string> listParams)
        {
            OperationReturn optReturn = new OperationReturn();

            optReturn.Result = true;
            optReturn.Code   = 0;
            try
            {
                if (listParams.Count < 3)
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_PARAM_INVALID;
                    optReturn.Message = string.Format("Param count invalid");
                    return(optReturn);
                }
                string strID, method, password;
                //0         UserID
                //1         Method(0:使用默认密码;1:使用指定的密码;2:特殊情况,19位用户编号+默认密码)
                //2         密码
                strID    = listParams[0];
                method   = listParams[1];
                password = listParams[2];
                string         rentToken = session.RentInfo.Token;
                string         passToDB;
                string         strSql;
                DataSet        objDataSet = null;
                EncryptionMode mode       = (EncryptionMode)Enum.Parse(typeof(EncryptionMode), "AES256V03Hex");
                if (method == "0")
                {
                    //从全局参数表查得默认密码
                    switch (session.DBType)
                    {
                    case 2:
                        strSql =
                            string.Format("SELECT C006 FROM T_11_001_{0} WHERE C002 = 11 AND C003 = {1}"
                                          , rentToken
                                          , S1101Consts.PARAM_DEFAULT_PASSWORD);
                        optReturn = MssqlOperation.GetDataSet(session.DBConnectionString, strSql);
                        if (!optReturn.Result)
                        {
                            return(optReturn);
                        }
                        objDataSet = optReturn.Data as DataSet;
                        break;

                    case 3:
                        strSql =
                            string.Format("SELECT C006 FROM T_11_001_{0} WHERE C002 = 11 AND C003 = {1}"
                                          , rentToken
                                          , S1101Consts.PARAM_DEFAULT_PASSWORD);
                        optReturn = OracleOperation.GetDataSet(session.DBConnectionString, strSql);
                        if (!optReturn.Result)
                        {
                            return(optReturn);
                        }
                        objDataSet = optReturn.Data as DataSet;
                        break;
                    }
                    if (objDataSet == null)
                    {
                        optReturn.Result  = false;
                        optReturn.Code    = Defines.RET_OBJECT_NULL;
                        optReturn.Message = string.Format("DataSet is null");
                        return(optReturn);
                    }
                    if (objDataSet.Tables[0].Rows.Count <= 0)
                    {
                        optReturn.Result  = false;
                        optReturn.Code    = Defines.RET_DBACCESS_NOT_EXIST;
                        optReturn.Message = string.Format("Globle param not exist.");
                        return(optReturn);
                    }
                    string defaultPass = objDataSet.Tables[0].Rows[0]["C006"].ToString();
                    defaultPass = DecryptFromDB(defaultPass);
                    defaultPass = defaultPass.Substring(8);
                    passToDB    = ServerAESEncryption.EncryptString(strID + defaultPass, mode);
                }
                else
                {
                    passToDB = ServerAESEncryption.EncryptString(strID + password, mode);
                }
                if (string.IsNullOrEmpty(passToDB))
                {
                    optReturn.Result  = false;
                    optReturn.Code    = Defines.RET_STRING_EMPTY;
                    optReturn.Message = string.Format("Password to database is empty");
                    return(optReturn);
                }
                switch (session.DBType)
                {
                case 2:
                    strSql =
                        string.Format(
                            "UPDATE T_11_005_{0} SET C004 = '{1}', C023 = '{2}' WHERE C001 = {3}",
                            rentToken,
                            passToDB,
                            DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd HH:mm:ss"),
                            strID);
                    optReturn = MssqlOperation.ExecuteSql(session.DBConnectionString, strSql);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    break;

                case 3:
                    strSql =
                        string.Format(
                            "UPDATE T_11_005_{0} SET C004 = '{1}', C023 = TO_DATE('{2}','YYYY-MM-DD HH24:MI:SS') WHERE C001 = {3}",
                            rentToken,
                            passToDB,
                            DateTime.Now.ToUniversalTime().ToString("yyyy/MM/dd HH:mm:ss"),
                            strID);
                    optReturn = OracleOperation.ExecuteSql(session.DBConnectionString, strSql);
                    if (!optReturn.Result)
                    {
                        return(optReturn);
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                optReturn.Result  = false;
                optReturn.Code    = Defines.RET_FAIL;
                optReturn.Message = ex.Message;
            }
            return(optReturn);
        }
示例#5
0
 public byte[] EncryptBytes(byte[] source, int mode)
 {
     return(ServerAESEncryption.EncryptBytes(source, (EncryptionMode)mode));
 }
示例#6
0
        void BtnDescrypt_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var typeItem = ListBoxType.SelectedItem as EncryptionTypeItem;
                var modeItem = ComboMode.SelectedItem as EncryptionModeItem;
                var encItem  = ListBoxEncoding.SelectedItem as EncryptionEncodingItem;
                if (typeItem == null || modeItem == null || encItem == null)
                {
                    return;
                }

                string strSource = TxtSource.Text;
                string strReturn = string.Empty;
                //string strTemp;

                int      mode     = (int)modeItem.Mode;
                int      type     = mode / 1000;
                Encoding encoding = encItem.Encoding;
                switch (type)
                {
                case 1:
                    //do
                    //{
                    //    if (strSource.Length > 128)
                    //    {
                    //        strTemp = strSource.Substring(0, 128);
                    //        strSource = strSource.Substring(128, strSource.Length - 128);
                    //    }
                    //    else
                    //    {
                    //        strTemp = strSource;
                    //        strSource = string.Empty;
                    //    }
                    //    if (typeItem.Value == 1)
                    //    {
                    //        strReturn += ClientAESEncryption.DecryptString(strTemp, modeItem.Mode, encoding);
                    //    }
                    //    else
                    //    {
                    //        strReturn += ServerAESEncryption.DecryptString(strTemp, modeItem.Mode, encoding);
                    //    }

                    //} while (strSource.Length > 0);
                    if (typeItem.Value == 1)
                    {
                        strReturn = ClientAESEncryption.DecryptString(strSource, modeItem.Mode, encoding);
                    }
                    else
                    {
                        strReturn += ServerAESEncryption.DecryptString(strSource, modeItem.Mode, encoding);
                    }
                    break;

                default:
                    ShowErrorMessage(string.Format("EncryptMode invalid.\t{0}", modeItem.Mode));
                    return;
                }
                AppendMessage(strReturn);
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
        }