public static void ExpireInDB(string paramValues, string strKey = null)
 {
     if (strKey == null)
     {
         strKey = ConfigurationManager.AppSettings[DEFAULT_KEY_NAME];
         if (string.IsNullOrEmpty(strKey))
         {
             throw (new SecurityException("Encryption key is not defined."));
         }
         if(strKey.StartsWith(CRYPTO_PREFIX)) {
             strKey = Crypto.Decrypt(strKey);
         }
     }
     SecureParams sp = new SecureParams(paramValues, strKey);
     string sid = sp[URL_ID_KEY];
     if (string.IsNullOrEmpty(sid))
     {
         return;
     }
     try
     {
         using (SqlCommand cmd = new SqlCommand("update url_params set expiration=getdate()-1 where id=@1"))
         {
             cmd.Parameters.AddWithValue("@1", sid);
             DBHelper.Instance.NonQuery(cmd);
         }
     }
     catch (Exception ex)
     {
         // TODO: handle exceptions
     }
 }
 /// <summary>
 /// Copy the contents of the given parameters into this instance.
 /// </summary>
 /// <param name="sp"></param>
 public void Copy(SecureParams sp)
 {
     foreach (string key in sp._hashParams.Keys)
     {
         _hashParams[key] = sp._hashParams[key];
     }
 }
Example #3
0
        public static void ExpireInDB(string paramValues, string strKey = null)
        {
            if (strKey == null)
            {
                strKey = ConfigurationManager.AppSettings[DEFAULT_KEY_NAME];
                if (string.IsNullOrEmpty(strKey))
                {
                    throw (new SecurityException("Encryption key is not defined."));
                }
                if (strKey.StartsWith(CRYPTO_PREFIX))
                {
                    strKey = Crypto.Decrypt(strKey);
                }
            }
            SecureParams sp  = new SecureParams(paramValues, strKey);
            string       sid = sp[URL_ID_KEY];

            if (string.IsNullOrEmpty(sid))
            {
                return;
            }
            try
            {
                using (SqlCommand cmd = new SqlCommand("update url_params set expiration=getdate()-1 where id=@1"))
                {
                    cmd.Parameters.AddWithValue("@1", sid);
                    DBHelper.Instance.NonQuery(cmd);
                }
            }
            catch (Exception ex)
            {
                // TODO: handle exceptions
            }
        }
Example #4
0
        public static SecureParams FromDB(string paramValues, string strKey = null)
        {
            if (strKey == null)
            {
                strKey = ConfigurationManager.AppSettings[DEFAULT_KEY_NAME];
                if (string.IsNullOrEmpty(strKey))
                {
                    throw (new SecurityException("Encryption key is not defined."));
                }
                if (strKey.StartsWith(CRYPTO_PREFIX))
                {
                    strKey = Crypto.Decrypt(strKey);
                }
            }
            SecureParams sp  = new SecureParams(paramValues, strKey);
            string       sid = sp[URL_ID_KEY];

            if (string.IsNullOrEmpty(sid))
            {
                return(sp);
            }
            try
            {
                using (SqlCommand cmd = new SqlCommand("select params from url_params (nolock) where id=@1 and expiration > getdate()"))
                {
                    cmd.Parameters.AddWithValue("@1", sid);
                    object obj = DBHelper.Instance.Scalar(cmd);
                    if (obj != null && obj != DBNull.Value)
                    {
                        sp = new SecureParams(obj.ToString(), strKey);
                        return(sp);
                    }
                }
            }
            catch (Exception ex)
            {
                // TODO: Handle exceptions
            }
            return(null);
        }
 public static SecureParams FromDB(string paramValues, string strKey = null)
 {
     if (strKey == null)
     {
         strKey = ConfigurationManager.AppSettings[DEFAULT_KEY_NAME];
         if (string.IsNullOrEmpty(strKey))
         {
             throw (new SecurityException("Encryption key is not defined."));
         }
         if(strKey.StartsWith(CRYPTO_PREFIX)) {
             strKey = Crypto.Decrypt(strKey);
         }
     }
     SecureParams sp = new SecureParams(paramValues, strKey);
     string sid = sp[URL_ID_KEY];
     if (string.IsNullOrEmpty(sid))
     {
         return (sp);
     }
     try
     {
         using (SqlCommand cmd = new SqlCommand("select params from url_params (nolock) where id=@1 and expiration > getdate()"))
         {
             cmd.Parameters.AddWithValue("@1", sid);
             object obj = DBHelper.Instance.Scalar(cmd);
             if (obj != null && obj != DBNull.Value)
             {
                 sp = new SecureParams(obj.ToString(), strKey);
                 return (sp);
             }
         }
     }
     catch (Exception ex)
     {
         // TODO: Handle exceptions
     }
     return (null);
 }
 /// <summary>
 /// Copy the contents of the given parameters into this instance.
 /// </summary>
 /// <param name="sp"></param>
 public void Copy(SecureParams sp)
 {
     foreach (string key in sp._hashParams.Keys)
     {
         _hashParams[key] = sp._hashParams[key];
     }
 }