Exemplo n.º 1
0
        void BtnGetPassword_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var typeItem = ListBoxType.SelectedItem as EncryptionTypeItem;
                var modeItem = ComboMode.SelectedItem as EncryptionModeItem;
                if (typeItem == null || modeItem == null)
                {
                    return;
                }

                string strSource = TxtSource.Text;
                string strID     = TxtID.Text;
                if (string.IsNullOrEmpty(strSource) ||
                    string.IsNullOrEmpty(strID))
                {
                    ShowErrorMessage(string.Format("Password or ID empty"));
                    return;
                }
                strSource = strID + strSource;
                byte[] temp = ServerHashEncryption.EncryptBytes(Encoding.Unicode.GetBytes(strSource),
                                                                EncryptionMode.SHA512V00Hex);
                var aes = ServerAESEncryption.EncryptBytes(temp, EncryptionMode.AES256V02Hex);
                AppendMessage(string.Format("{0}", ServerEncryptionUtils.Byte2Hex(aes)));
            }
            catch (Exception ex)
            {
                ShowErrorMessage(ex.Message);
            }
        }
Exemplo n.º 2
0
 private string EncryptShaToDB(string strSource)
 {
     try
     {
         return(ServerHashEncryption.EncryptString(strSource, EncryptionMode.SHA512V00Hex));
     }
     catch
     {
         return(strSource);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 ///  用户密码加密
 /// </summary>
 /// <param name="strUserID"></param>
 /// <param name="strPwdInput"></param>
 /// <returns></returns>
 public static string EncryptUserPwd(string strUserID, string strPwdInput)
 {
     try
     {
         string str  = strUserID + strPwdInput;
         byte[] temp = ServerHashEncryption.EncryptBytes(Encoding.Unicode.GetBytes(str),
                                                         EncryptionMode.SHA512V00Hex);
         var aes = ServerAESEncryption.EncryptBytes(temp, EncryptionMode.AES256V02Hex);
         return(ServerEncryptionUtils.Byte2Hex(aes));
     }
     catch
     {
         return(strUserID + strPwdInput);
     }
 }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        private string GenerateToken(LoggingServerInfo info)
        {
            string strCode = string.Format("{0}{1}", mToken, info.HostAddress);

            return(ServerHashEncryption.EncryptString(strCode, EncryptionMode.SHA256V00Hex));
        }
Exemplo n.º 6
0
        void BtnEncrypt_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.EncryptString(strTemp, modeItem.Mode, encoding);
                    //    }
                    //    else
                    //    {
                    //        strReturn += ServerAESEncryption.EncryptString(strTemp, modeItem.Mode, encoding);
                    //    }

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

                case 2:
                case 3:
                    if (typeItem.Value == 1)
                    {
                        strReturn += ClientHashEncryption.EncryptString(strSource, modeItem.Mode, encoding);
                    }
                    else
                    {
                        strReturn += ServerHashEncryption.EncryptString(strSource, modeItem.Mode, encoding);
                    }
                    break;

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