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]; } }
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 } }
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); }