/// <summary> /// Generates symmetric encrypted string representing the user. This method is supposed to be used to authenticate /// web service requests or other 'out-of-context' requests /// </summary> /// <returns>encrypted representation of user</returns> public string EncryptPrincipal() { string s = ((UserIdentity)this.identity).ID + "|" + this.identity.Name; foreach (string r in this.roles) { s += "|" + r; } //return Dury.SiteFoundry.Security.Cryptography.Symmetric.EncryptData(SFGlobal.EncryptionKey,s); Dury.SiteFoundry.Security.Cryptography.SymmetricEncryption se = new Dury.SiteFoundry.Security.Cryptography.SymmetricEncryption(); return(se.EncryptString(s, SFGlobal.EncryptionKey)); }
public static UserPrincipal CreateUserPrincipal(string encryptedString) { Dury.SiteFoundry.Security.Cryptography.SymmetricEncryption se = new Dury.SiteFoundry.Security.Cryptography.SymmetricEncryption(); try { ArrayList groups = new ArrayList(se.DecryptString(encryptedString, SFGlobal.EncryptionKey).Split('|')); int userID = int.Parse((string)groups[0]); string username = (string)groups[1]; groups.RemoveRange(0, 2); return(CreateUserPrincipal(userID, username, groups)); } catch (Exception e) { throw new DuryTools.ErrorHandler("user decrypt failed", e); } }