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; }
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; }
/// <summary> /// Utility method to decrypt text /// </summary> /// <param name="text"></param> public static String Decrypt(String text) { TextEncryption crypto = new TextEncryption(); return crypto.Decrypt(text); }