public string ToEncryptedTicket ()
{
string roles = string.Join (",", GetRoles ());
string cookiePath = RoleManagerConfig.CookiePath;
int approxTicketLen = roles.Length + cookiePath.Length + 64;
if (_cachedArray.Length > Roles.MaxCachedResults)
return null;
MemoryStream ticket = new MemoryStream (approxTicketLen);
BinaryWriter writer = new BinaryWriter (ticket);
// version
writer.Write (Version);
// issue datetime
DateTime issueDate = DateTime.Now;
writer.Write (issueDate.Ticks);
// expiration datetime
writer.Write (_expireDate.Ticks);
writer.Write (cookiePath);
writer.Write (roles);
CookieProtection cookieProtection = RoleManagerConfig.CookieProtection;
byte[] ticket_data = ticket.GetBuffer ();
if (cookieProtection == CookieProtection.All) {
ticket_data = MachineKeySectionUtils.EncryptSign (MachineConfig, ticket_data);
} else if (cookieProtection == CookieProtection.Encryption) {
ticket_data = MachineKeySectionUtils.Encrypt (MachineConfig, ticket_data);
} else if (cookieProtection == CookieProtection.Validation) {
ticket_data = MachineKeySectionUtils.Sign (MachineConfig, ticket_data);
}
return GetBase64FromBytes (ticket_data, 0, ticket_data.Length);
}