public static String Encode(String text) { String result = null; if (text != null) result = new TextEncryption().Encrypt(text); return result; }
public static String Decode(String encrypted) { String result = null; if (encrypted != null) { try { result = new TextEncryption().Decrypt(encrypted); } catch (Exception){} } return result; }
public static Boolean IsValid(String expectedData, String encryptedData) { Boolean result = false; try { TextEncryption crypto = new TextEncryption(GooeyConfigManager.TokenEncyrptionKey); String data = crypto.Decrypt(encryptedData); String[] fields = data.Split(','); if (fields.Length == 3) { String original = fields[1]; String timestamp = fields[2]; if (expectedData.EqualsCaseInsensitive(original)) { //DateTime dt = DateTime.Parse(timestamp); //if (dt > DateTime.Now) //{ //check the database to make sure this token hasn't been used SecurityToken temp = GetFromDatabase(encryptedData); if (temp != null) { int uses = temp.Uses + 1; if (uses <= temp.MaxUses) { //Update the use count in the database temp.Uses = uses; SaveToDatabase(temp); result = true; } } //} } } } catch (Exception) { } return result; }
public static String Issue(String data, TimeSpan validFor, Int32 maxUses) { if (data.Length > 90) throw new ArgumentException("The data for the token cannot be longer than 90 characters"); DateTime issued = UtcDateTime.Now; DateTime expires = issued.Add(validFor); data = Guid.NewGuid().ToString() + "," + data + "," + expires.Ticks; TextEncryption crypto = new TextEncryption(GooeyConfigManager.TokenEncyrptionKey); String result = crypto.Encrypt(data); SecurityToken token = new SecurityToken(); token.Token = result; token.Issued = issued; token.Expires = expires; token.Uses = 0; token.MaxUses = maxUses; SaveToDatabase(token); return result; }
/// <summary> /// Gets the GUID of the active site. /// If it's a production site, it'll return the GUID based upon the domain or staging TLD /// If it's in the control panel, it'll return the active site being managed. /// </summary> /// <param name="isRequired"></param> /// <returns></returns> public static Data.Guid GetActiveSiteGuid(Boolean isRequired) { if (HttpContext.Current == null) throw new ApplicationException("The request context was not availabe. To rerieve the active site you must be running from within IIS or Azure"); Data.Guid result; //Check if we're running outside the admin... if so, base the active site upon the domain String host = HttpContext.Current.Request.Url.Host; String path = HttpContext.Current.Request.Url.PathAndQuery; if ((GooeyConfigManager.AdminSiteHost.EqualsCaseInsensitive(host)) || (path.Contains("forward-init.mxl"))) { HttpCookie cookie = HttpContext.Current.Request.Cookies["selected-site"]; String guid = (cookie != null) ? (cookie.Value) : ""; if ((isRequired) && (String.IsNullOrEmpty(guid))) throw new ArgumentException("No site has been selected to manage themes for or cookies are disabled."); if (!String.IsNullOrEmpty(guid)) guid = new TextEncryption().Decrypt(guid); result = Data.Guid.New(guid); } else { String cacheKey = host.ToLower(); result = siteGuidCache.GetValue<String, Data.Guid>(cacheKey); if (result.IsEmpty()) { CmsSubscription subscription = SubscriptionManager.GetSubscriptionForDomain(host); if (subscription != null) { result = Data.Guid.New(subscription.Guid); siteGuidCache.Add(cacheKey, result); } } } return result; }
public static void SetActiveSiteCookie(String guid) { if (String.IsNullOrEmpty(guid)) throw new ArgumentException("A site guid must be specified when setting the active site."); String encrypted = new TextEncryption().Encrypt(guid); HttpContext.Current.Response.Cookies["selected-site"].Value = encrypted; }
public static String Encrypt(String text) { TextEncryption crypto = new TextEncryption(); return crypto.Encrypt(text); }
private static void SetEncryptedSiteConfiguration(String key, String value) { TextEncryption crypto = new TextEncryption(CurrentSite.Guid.Value); String encryptedValue = crypto.Encrypt(value); SetSiteConfiguration(key, encryptedValue); }
private static String GetEncryptedSiteConfiguration(String key) { String result = null; String encrypted = GetSiteConfiguration(key, null, false); if (encrypted != null) { try { TextEncryption crypto = new TextEncryption(CurrentSite.Guid.Value); result = crypto.Decrypt(encrypted); } catch (Exception) { } } return result; }