Ejemplo n.º 1
0
        /// <summary>
        /// Sessions the info to string.
        /// </summary>
        /// <param name="sessionInfo">The session info.</param>
        /// <returns></returns>
        public static string SessionInfoToString(SessionInfo sessionInfo)
        {
            if (sessionInfo == null)
                return null;

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            XmlSerializer xml = new XmlSerializer(typeof(SessionInfo));
            xml.Serialize(sw, sessionInfo);
            sw.Flush();

            CryptoString cry = new CryptoString(_key, CryptoString.Method.Encrypt, sb.ToString());
            string ret = cry.Execute();
            sb.Remove(0, sb.Length);
            if (Regex.IsMatch(ret, @".*[Oo][Nn][a-zA-Z]*=*$"))
            {
                sessionInfo.ConnectionString += ';';
                xml.Serialize(sw, sessionInfo);
                sw.Flush();
                cry = new CryptoString(_key, CryptoString.Method.Encrypt, sb.ToString());
                ret = cry.Execute();
            }

            sw.Close();
            return ret;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sessions the info to string.
        /// </summary>
        /// <param name="sessionInfo">The session info.</param>
        /// <returns></returns>
        public static string SessionInfoToString(SessionInfo sessionInfo)
        {
            if (sessionInfo == null)
            {
                return(null);
            }

            StringBuilder sb = new StringBuilder();
            StringWriter  sw = new StringWriter(sb);

            XmlSerializer xml = new XmlSerializer(typeof(SessionInfo));

            xml.Serialize(sw, sessionInfo);
            sw.Flush();

            CryptoString cry = new CryptoString(_key, CryptoString.Method.Encrypt, sb.ToString());
            string       ret = cry.Execute();

            sb.Remove(0, sb.Length);
            if (Regex.IsMatch(ret, @".*[Oo][Nn][a-zA-Z]*=*$"))
            {
                sessionInfo.ConnectionString += ';';
                xml.Serialize(sw, sessionInfo);
                sw.Flush();
                cry = new CryptoString(_key, CryptoString.Method.Encrypt, sb.ToString());
                ret = cry.Execute();
            }

            sw.Close();
            return(ret);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Strings to session info.
        /// </summary>
        /// <param name="src">The SRC.</param>
        /// <returns></returns>
        public static SessionInfo StringToSessionInfo(string src)
        {
            if (src == null)
            {
                return(null);
            }

            CryptoString  cry         = new CryptoString(_key, CryptoString.Method.Decrypt, src);
            StringReader  sr          = new StringReader(cry.Execute());
            XmlSerializer xml         = new XmlSerializer(typeof(SessionInfo));
            SessionInfo   sessionInfo = (SessionInfo)xml.Deserialize(sr);

            sr.Close();

            return(sessionInfo);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor - Pass key, and encrypt/decrypt action, and text to encrypt and decrypt.
 /// </summary>
 /// <param name="Key">Key to hash</param>
 /// <param name="Action">Encrypt/Decrypt</param>
 /// <param name="Text">Text to Encrypt/Decrypt</param>
 public CryptoString(string Key, CryptoString.Method Action, string Text)
 {
     _keyValue = Key;
     _textValue = Text;
     _encyptAction = Action;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Constructor - Pass key and encrypt/decrypt action
 /// </summary>
 /// <param name="Key">Key to hash</param>
 /// <param name="Action">Encrypt/Descrypt</param>
 public CryptoString(string Key, CryptoString.Method Action)
 {
     _keyValue = Key;
     _encyptAction = Action;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Strings to session info.
        /// </summary>
        /// <param name="src">The SRC.</param>
        /// <returns></returns>
        public static SessionInfo StringToSessionInfo(string src)
        {
            if (src == null)
                return null;

            CryptoString cry = new CryptoString(_key, CryptoString.Method.Decrypt, src);
            StringReader sr = new StringReader(cry.Execute());
            XmlSerializer xml = new XmlSerializer(typeof(SessionInfo));
            SessionInfo sessionInfo = (SessionInfo)xml.Deserialize(sr);
            sr.Close();

            return sessionInfo;
        }