Пример #1
0
        private void LoadFromCookie()
        {
            ID = Guid.NewGuid();
            var cookie = m_httpCtx.Request.Cookies[CookieName];

            // decrypt existing and set sessionid
            if (cookie != null)
            {
                try
                {
                    string sessionIDString = CryptUtil.Decrypt(cookie.Value);
                    Guid   temp;
                    if (Guid.TryParse(sessionIDString, out temp))
                    {
                        ID = temp;
                    }
                }
                catch
                {
                    // if anything fails fallback to new sessionid
                    Debug.WriteLine("Session cookie could not be decrypted!");
                    SaveToCookie();
                }
            }
        }
Пример #2
0
 public static string GetPlainValue(EncryptedField field)
 {
     if (field == null)
     {
         return((string)null);
     }
     return(!field.IsEncrypted ? field.Value : CryptUtil.Decrypt(field.Value));
 }
 public void Decrypt()
 {
     foreach (ADServerElement server in ADServers)
     {
         if (server.Password != null)
         {
             if (server.Password.StartsWith(EncodePrefix))
             {
                 server.Password = CryptUtil.Decrypt(server.Password.Substring(EncodePrefix.Length));
             }
         }
     }
 }
Пример #4
0
        public T Deserialize <T>(byte[] bytes)
        {
            if (ShouldCrypt)
            {
                bytes = CryptUtil.Decrypt(bytes, password, salt, iterations);
            }
            if (compress)
            {
                bytes = CompressUtil.Decompress(bytes);
            }
            var json = System.Text.Encoding.UTF8.GetString(bytes);

            return(JsonUtility.FromJson <T>(json));
        }
Пример #5
0
        private void WriteSkeleton(UserProfile userProfile)
        {
            bool flag = false;

            if (userProfile.SessionID != null && !string.IsNullOrEmpty(userProfile.SessionID.Value))
            {
                flag = true;
            }
            this._Writer.WriteStartDocument();
            this._Writer.WriteStartElement("__InSite");
            this._Writer.WriteAttributeString("__version", "1.1");
            this._Writer.WriteAttributeString("__encryption", "2");
            this._Writer.WriteStartElement("__session");
            if (!string.IsNullOrEmpty(userProfile.FilterTags) || !string.IsNullOrEmpty(userProfile.FilterTagAccess))
            {
                this._Writer.WriteStartElement("__filter");
                if (!string.IsNullOrEmpty(userProfile.FilterTags))
                {
                    this._Writer.WriteStartElement("__tags");
                    this._Writer.WriteCData(userProfile.FilterTags);
                    this._Writer.WriteEndElement();
                }
                if (!string.IsNullOrEmpty(userProfile.FilterTagAccess) && int.TryParse(userProfile.FilterTagAccess, out int _))
                {
                    this._Writer.WriteStartElement("__allowUntaggedInstances");
                    this._Writer.WriteCData(userProfile.FilterTagAccess);
                    this._Writer.WriteEndElement();
                }
                this._Writer.WriteEndElement();
            }
            if (!string.IsNullOrEmpty(userProfile.Dictionary))
            {
                this._Writer.WriteStartElement("__language");
                this._Writer.WriteStartElement("__name");
                this._Writer.WriteCData(userProfile.Dictionary);
                this._Writer.WriteEndElement();
                this._Writer.WriteEndElement();
            }
            if (flag)
            {
                this._Writer.WriteStartElement("__useSession");
            }
            else
            {
                this._Writer.WriteStartElement("__connect");
            }
            this._Writer.WriteStartElement("user");
            this._Writer.WriteStartElement("__name");
            this._Writer.WriteCData(userProfile.Name);
            this._Writer.WriteEndElement();
            this._Writer.WriteEndElement();
            EncryptedField encryptedField;

            if (flag)
            {
                encryptedField = userProfile.SessionID;
                this._Writer.WriteStartElement("sessionId");
            }
            else
            {
                encryptedField = userProfile.Password;
                this._Writer.WriteStartElement("password");
            }
            this._Writer.WriteAttributeString("__encrypted", "no");
            if (encryptedField != null)
            {
                if (encryptedField.IsEncrypted)
                {
                    this._Writer.WriteCData(CryptUtil.Decrypt(encryptedField.Value));
                }
                else
                {
                    this._Writer.WriteCData(encryptedField.Value);
                }
            }
            else
            {
                this._Writer.WriteCData(string.Empty);
            }
            this._Writer.WriteEndElement();
            this._Writer.WriteEndElement();
            this._Writer.WriteEndElement();
        }