Adds Encryption/Decryption string extension methods that work in medium trust, with unit tests.

This commit is contained in:
Shannon Deminick
2013-01-15 01:35:10 +03:00
parent 0045ec353f
commit 5458c9a310
2 changed files with 33 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
namespace Umbraco.Core
{
@@ -18,6 +19,28 @@ namespace Umbraco.Core
///</summary>
public static class StringExtensions
{
/// <summary>
/// Encrypt the string using the MachineKey in medium trust
/// </summary>
/// <param name="toEncrypt"></param>
/// <returns></returns>
public static string EncryptWithMachineKey(this string toEncrypt)
{
var output = FormsAuthentication.Encrypt(new FormsAuthenticationTicket(0, "temp", DateTime.Now, DateTime.MaxValue, false, toEncrypt));
return output;
}
/// <summary>
/// Decrypt the encrypted string using the Machine key in medium trust
/// </summary>
/// <param name="encrypted"></param>
/// <returns></returns>
public static string DecryptWithMachineKey(this string encrypted)
{
var output = FormsAuthentication.Decrypt(encrypted);
return output.UserData;
}
//this is from SqlMetal and just makes it a bit of fun to allow pluralisation
public static string MakePluralName(this string name)
{