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
- XmlSchemaSearchPattern.cs
- DocumentCollection.cs
- FileDialog_Vista.cs
- ScopedKnownTypes.cs
- SqlServices.cs
- DynamicMethod.cs
- SymbolType.cs
- QilPatternVisitor.cs
- LineBreakRecord.cs
- ResourceBinder.cs
- TextRenderer.cs
- InternalControlCollection.cs
- HttpModuleCollection.cs
- XmlWrappingReader.cs
- SmiEventStream.cs
- PanningMessageFilter.cs
- backend.cs
- DesignerOptionService.cs
- XmlReader.cs
- XPathNodeHelper.cs
- NotSupportedException.cs
- SerializationBinder.cs
- RuntimeTransactionHandle.cs
- UnsafeNativeMethods.cs
- UnsafeNativeMethods.cs
- ExpressionBinding.cs
- XamlSerializationHelper.cs
- TypeDescriptor.cs
- ScanQueryOperator.cs
- SystemSounds.cs
- WorkflowInstanceProvider.cs
- GridView.cs
- ValueConversionAttribute.cs
- COM2Properties.cs
- StylusPointProperties.cs
- XmlDocumentSerializer.cs
- ControlPersister.cs
- BamlRecordWriter.cs
- OledbConnectionStringbuilder.cs
- ContainerSelectorBehavior.cs
- ColumnHeaderConverter.cs
- controlskin.cs
- ExceptionHelpers.cs
- CollectionConverter.cs
- FrameworkElementAutomationPeer.cs
- MenuRendererClassic.cs
- ContentPropertyAttribute.cs
- FrameworkElementAutomationPeer.cs
- FunctionParameter.cs
- cache.cs
- NumberFormatInfo.cs
- TemplateBindingExtension.cs
- COSERVERINFO.cs
- UTF8Encoding.cs
- ArrangedElementCollection.cs
- ConversionContext.cs
- DelegateTypeInfo.cs
- ColorAnimationUsingKeyFrames.cs
- ToolStripRendererSwitcher.cs
- SqlPersonalizationProvider.cs
- CodeSnippetStatement.cs
- DrawingContextDrawingContextWalker.cs
- KeyBinding.cs
- WebPartActionVerb.cs
- ProgressBar.cs
- XmlReaderSettings.cs
- DialogBaseForm.cs
- MatrixTransform3D.cs
- XmlSchemaProviderAttribute.cs
- ScriptReferenceEventArgs.cs
- HtmlGenericControl.cs
- CompilationSection.cs
- PropertyBuilder.cs
- peersecurityelement.cs
- SoapEnumAttribute.cs
- DeferredTextReference.cs
- SoundPlayer.cs
- XsltSettings.cs
- DataControlFieldTypeEditor.cs
- MouseCaptureWithinProperty.cs
- PartManifestEntry.cs
- SqlUtil.cs
- CollectionChangeEventArgs.cs
- IDispatchConstantAttribute.cs
- SamlDelegatingWriter.cs
- DispatcherFrame.cs
- DifferencingCollection.cs
- webproxy.cs
- DocumentPage.cs
- DesignerActionTextItem.cs
- WebPartConnectionsCancelEventArgs.cs
- SystemException.cs
- SimpleMailWebEventProvider.cs
- FormViewActionList.cs
- View.cs
- MailMessage.cs
- ValidationRule.cs
- ComponentCollection.cs
- XmlUtil.cs
- IMembershipProvider.cs