예제 #1
0
        bool ReEncryptKey(string oldPassword, string newPassword)
        {
            HttpContext context  = HiContext.Current.Context;
            XmlDocument document = new XmlDocument();
            string      filename = context.Request.MapPath(Globals.ApplicationPath + "/config/key.config");
            string      str2     = context.Request.MapPath(Globals.ApplicationPath + "/config/key.config.bak");

            try
            {
                document.Load(filename);
            }
            catch
            {
                document.Load(str2);
            }
            if (int.Parse(document.SelectSingleNode("Settings/Token").InnerText) == this.UserId)
            {
                XmlNode node      = document.SelectSingleNode("Settings/Key");
                byte[]  plaintext = Cryptographer.DecryptWithPassword(Convert.FromBase64String(node.InnerText), oldPassword);
                node.InnerText = Convert.ToBase64String(Cryptographer.EncryptWithPassword(plaintext, newPassword));
                document.Save(filename);
                document.Save(str2);
            }
            return(true);
        }
예제 #2
0
        public static LoginUserStatus ValidLogin(SiteManager manager)
        {
            if (manager == null)
            {
                return(LoginUserStatus.InvalidCredentials);
            }
            LoginUserStatus status = Users.ValidateUser(manager);

            if ((status == LoginUserStatus.Success) && (manager.UserRole == UserRole.SiteManager))
            {
                HttpContext context = HiContext.Current.Context;
                string      path    = context.Request.MapPath(Globals.ApplicationPath + "/config/Hishop.key");
                if (File.Exists(path))
                {
                    return(status);
                }
                try
                {
                    XmlDocument document = new XmlDocument();
                    try
                    {
                        document.Load(context.Request.MapPath(Globals.ApplicationPath + "/config/key.config"));
                    }
                    catch
                    {
                        document.Load(context.Request.MapPath(Globals.ApplicationPath + "/config/key.config.bak"));
                    }
                    if (int.Parse(document.SelectSingleNode("Settings/Token").InnerText) != manager.UserId)
                    {
                        return(status);
                    }
                    byte[] userData     = Cryptographer.DecryptWithPassword(Convert.FromBase64String(document.SelectSingleNode("Settings/Key").InnerText), manager.Password);
                    byte[] encryptedKey = ProtectedData.Protect(userData, null, DataProtectionScope.LocalMachine);
                    using (Stream stream = new FileStream(path, FileMode.Create))
                    {
                        KeyManager.Write(stream, encryptedKey, DataProtectionScope.LocalMachine);
                    }
                    CryptographyUtility.ZeroOutBytes(encryptedKey);
                    CryptographyUtility.ZeroOutBytes(userData);
                }
                catch
                {
                }
            }
            return(status);
        }