Esempio n. 1
0
        //
        //====================================================================================================
        /// <summary>
        /// return a DES encrypted string. This is a two way so use it for little sister security, not foreign government security
        /// </summary>
        /// <param name="sourceToEncrypt"></param>
        /// <returns></returns>
        private static string encryptDes(CoreController core, string sourceToEncrypt)
        {
            string returnResult = "";

            try {
                if (string.IsNullOrEmpty(core.appConfig.privateKey))
                {
                    //
                }
                else
                {
                    // Compute has key using DES
                    byte[] saltBytes = ASCIIEncoding.ASCII.GetBytes("notsorandomsalt");
                    byte[] key       = ASCIIEncoding.ASCII.GetBytes(HashEncode.computeHash(core.appConfig.privateKey, "SHA512", saltBytes));
                    Array.Resize(ref key, 24);
                    TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider {
                        Key  = key,
                        Mode = CipherMode.ECB
                    };
                    ICryptoTransform DESEncrypt = DES.CreateEncryptor();
                    byte[]           Buffer     = ASCIIEncoding.ASCII.GetBytes(sourceToEncrypt);
                    Buffer       = DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length);
                    returnResult = Convert.ToBase64String(Buffer);
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnResult);
        }
Esempio n. 2
0
        //
        //====================================================================================================
        /// <summary>
        /// return an encrypted string. This is a one way so use it passwords, etc.
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string oneWayEncrypt(CoreController core, string password)
        {
            string returnResult = "";

            try {
                returnResult = HashEncode.computeHash(password, "SHA512", null);
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnResult);
        }
Esempio n. 3
0
        //
        //====================================================================================================
        /// <summary>
        /// return true if an encrypted string matches an unencrypted string.
        /// </summary>
        /// <param name="sourceToTest"></param>
        /// <returns></returns>
        public static bool oneWayVerify(CoreController core, string sourceToTest, string encryptedToken)
        {
            bool returnResult = false;

            try {
                returnResult = HashEncode.verifyHash(sourceToTest, "SHA512", encryptedToken);
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnResult);
        }
Esempio n. 4
0
        public ActionResult CheckLogin(LoginVM loginVM)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var userName = loginVM.UserName;
                    var password = loginVM.Password;
                    if (string.IsNullOrEmpty(userName))
                    {
                        return(Json(new { Success = false, ErrorMessage = "请输入用户名" }, JsonRequestBehavior.AllowGet));
                    }
                    if (string.IsNullOrEmpty(password))
                    {
                        return(Json(new { Success = false, ErrorMessage = "请输入密码" }, JsonRequestBehavior.AllowGet));
                    }

                    var checkedPass = ValidateCode == loginVM.ValidateCode;
                    //检验验证码
                    if (LoginHelper.IsAllowValidateCode && !checkedPass)
                    {
                        return(Json(new { Success = false, ErrorMessage = string.IsNullOrWhiteSpace(ValidateCode) ? "验证码失效" : "验证码错误" }, JsonRequestBehavior.AllowGet));
                    }
                    //解密的密码
                    var pPassword = JSDes.DesDecrypt(password, loginVM.LoginSecretKey);
                    //将明文密码转化为MD5加密
                    password = HashEncode.HashEncoding(pPassword);

                    var user = LoginHelper.GetLoginUserInfo(StringSafeFilter.Filter(loginVM.UserName), StringSafeFilter.Filter(password.ToUpper()));
                    if (user == null)
                    {
                        //用户名或密码有误!
                        return(Json(new { Success = false, ErrorMessage = "用户名或密码有误" }, JsonRequestBehavior.AllowGet));
                    }
                    LoginHelper.SaveUserInfoToSession(user);
                    return(RedirectToAction("Index", "Home"));
                }
                catch
                {
                }
            }
            return(Json(new { Success = true }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 5
0
        //
        //====================================================================================================
        /// <summary>
        /// return a DES decrypted string. blank or non-base64 strings return an empty string. Exception thrown if decryption error. This is a two way so use it for little sister security, not foreign government security
        /// </summary>
        /// <param name="sourceToDecrypt"></param>
        /// <returns></returns>
        private static string decryptDes(CoreController core, string sourceToDecrypt)
        {
            string returnResult = "";

            try {
                if (string.IsNullOrEmpty(sourceToDecrypt))
                {
                    //
                    // -- source blank, decrypt to blank
                }
                else if (!sourceToDecrypt.isBase64String())
                {
                    //
                    // -- source invalid, decrypt to blank
                }
                else
                {
                    byte[] saltBytes = ASCIIEncoding.ASCII.GetBytes("notsorandomsalt");
                    byte[] key       = ASCIIEncoding.ASCII.GetBytes(HashEncode.computeHash(core.appConfig.privateKey, "SHA512", saltBytes));
                    Array.Resize(ref key, 24);
                    byte[] buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(core.appConfig.privateKey);
                    TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider {
                        Key  = key,
                        Mode = CipherMode.ECB
                    };
                    ICryptoTransform DESDecrypt = DES.CreateDecryptor();
                    buffer = Convert.FromBase64String(sourceToDecrypt);
                    try {
                        returnResult = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypt.TransformFinalBlock(buffer, 0, buffer.Length));
                    } catch (Exception ex) {
                        LogController.logError(core, ex);
                        throw;
                    }
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnResult);
        }