Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Security / CookieProtection.cs / 1305376 / CookieProtection.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.Security
{
using System.Security.Cryptography;
using System.Web.Configuration;
using System.Web.Management;
public enum CookieProtection
{
None, Validation, Encryption, All
}
internal class CookieProtectionHelper
{
internal static string Encode (CookieProtection cookieProtection, byte [] buf, int count)
{
if (cookieProtection == CookieProtection.All || cookieProtection == CookieProtection.Validation)
{
byte[] bMac = MachineKeySection.HashData (buf, null, 0, count);
if (bMac == null)
return null;
if (buf.Length >= count + bMac.Length)
{
Buffer.BlockCopy (bMac, 0, buf, count, bMac.Length);
}
else
{
byte[] bTemp = buf;
buf = new byte[count + bMac.Length];
Buffer.BlockCopy (bTemp, 0, buf, 0, count);
Buffer.BlockCopy (bMac, 0, buf, count, bMac.Length);
}
count += bMac.Length;
}
if (cookieProtection == CookieProtection.All || cookieProtection == CookieProtection.Encryption)
{
buf = MachineKeySection.EncryptOrDecryptData (true, buf, null, 0, count);
count = buf.Length;
}
if (count < buf.Length)
{
byte[] bTemp = buf;
buf = new byte[count];
Buffer.BlockCopy (bTemp, 0, buf, 0, count);
}
return HttpServerUtility.UrlTokenEncode(buf);
}
internal static byte[] Decode (CookieProtection cookieProtection, string data)
{
byte [] buf = HttpServerUtility.UrlTokenDecode(data);
if (buf == null || cookieProtection == CookieProtection.None)
return buf;
if (cookieProtection == CookieProtection.All || cookieProtection == CookieProtection.Encryption)
{
buf = MachineKeySection.EncryptOrDecryptData (false, buf, null, 0, buf.Length);
if (buf == null)
return null;
}
if (cookieProtection == CookieProtection.All || cookieProtection == CookieProtection.Validation)
return MachineKeySection.GetUnHashedData(buf);
return buf;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HtmlImage.cs
- SafeLocalMemHandle.cs
- AssemblyAttributes.cs
- XmlTextWriter.cs
- EventData.cs
- CollectionViewGroupRoot.cs
- BaseCodeDomTreeGenerator.cs
- BindingElementExtensionElement.cs
- WorkflowMarkupElementEventArgs.cs
- ToolStripContentPanel.cs
- ADRoleFactory.cs
- ListViewContainer.cs
- HttpInputStream.cs
- ProjectionCamera.cs
- MethodRental.cs
- SqlCommand.cs
- ConfigurationSectionCollection.cs
- WebPartTransformerCollection.cs
- GridViewHeaderRowPresenter.cs
- DataBoundControlHelper.cs
- XmlHelper.cs
- HttpModulesSection.cs
- InlinedAggregationOperator.cs
- SendOperation.cs
- PermissionSet.cs
- OutOfProcStateClientManager.cs
- InvalidEnumArgumentException.cs
- DockProviderWrapper.cs
- PlaceHolder.cs
- ListBindingHelper.cs
- WsatTransactionHeader.cs
- ModifyActivitiesPropertyDescriptor.cs
- FormatConvertedBitmap.cs
- DesignerUtility.cs
- hresults.cs
- FactoryMaker.cs
- EntryPointNotFoundException.cs
- FormsAuthenticationCredentials.cs
- UserInitiatedNavigationPermission.cs
- Group.cs
- CompareValidator.cs
- KnownTypes.cs
- LinqDataSourceSelectEventArgs.cs
- TriggerActionCollection.cs
- Crypto.cs
- PageParser.cs
- SurrogateSelector.cs
- _UriSyntax.cs
- IndentedWriter.cs
- ManualResetEvent.cs
- FrameworkElementAutomationPeer.cs
- GB18030Encoding.cs
- DataViewManagerListItemTypeDescriptor.cs
- WindowsStartMenu.cs
- SettingsPropertyValueCollection.cs
- X509InitiatorCertificateServiceElement.cs
- Action.cs
- PathSegmentCollection.cs
- XmlNamespaceManager.cs
- EntityDataSourceConfigureObjectContext.cs
- TimeEnumHelper.cs
- FreezableDefaultValueFactory.cs
- NavigationService.cs
- WmlTextBoxAdapter.cs
- SecurityResources.cs
- Repeater.cs
- ObjectDataSourceDesigner.cs
- SamlAuthenticationClaimResource.cs
- Shape.cs
- InfiniteTimeSpanConverter.cs
- CodeCommentStatementCollection.cs
- ReadOnlyDataSource.cs
- ClrPerspective.cs
- WebBrowsableAttribute.cs
- SharedPerformanceCounter.cs
- ThousandthOfEmRealPoints.cs
- TraceHwndHost.cs
- TypeUtils.cs
- WithStatement.cs
- TdsParserStaticMethods.cs
- SystemGatewayIPAddressInformation.cs
- PreservationFileReader.cs
- OAVariantLib.cs
- RandomNumberGenerator.cs
- bidPrivateBase.cs
- CacheForPrimitiveTypes.cs
- EventSourceCreationData.cs
- TickBar.cs
- RootProfilePropertySettingsCollection.cs
- DLinqDataModelProvider.cs
- StrongName.cs
- ClientApiGenerator.cs
- CheckedListBox.cs
- GeneralTransform3DTo2D.cs
- HotSpotCollectionEditor.cs
- MenuAdapter.cs
- EncryptedReference.cs
- TypeNameHelper.cs
- TableLayoutRowStyleCollection.cs
- CryptoApi.cs