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
- OracleConnectionString.cs
- WsatAdminException.cs
- MessageBox.cs
- PropertyMapper.cs
- ViewStateException.cs
- NumberFormatter.cs
- RenderTargetBitmap.cs
- PriorityBindingExpression.cs
- ProcessModule.cs
- SimpleType.cs
- ModelItemDictionary.cs
- ChangeProcessor.cs
- AspCompat.cs
- ProfilePropertySettings.cs
- ProgressBar.cs
- DoubleStorage.cs
- RowUpdatedEventArgs.cs
- IChannel.cs
- UmAlQuraCalendar.cs
- PrintPreviewGraphics.cs
- FormParameter.cs
- StreamReader.cs
- WebBrowserPermission.cs
- OpCodes.cs
- ExtensionFile.cs
- MetaData.cs
- MemoryRecordBuffer.cs
- ProfileSection.cs
- ResourcePart.cs
- DataGridViewColumn.cs
- HtmlElement.cs
- TypeTypeConverter.cs
- ResourceManagerWrapper.cs
- MemberAccessException.cs
- WCFModelStrings.Designer.cs
- DocumentPage.cs
- Compiler.cs
- XmlILModule.cs
- SHA1Managed.cs
- OptimalBreakSession.cs
- TabControlDesigner.cs
- AbstractExpressions.cs
- AnnotationDocumentPaginator.cs
- WriteableBitmap.cs
- EventLogger.cs
- Stream.cs
- ShapingWorkspace.cs
- XPathCompileException.cs
- TypedTableHandler.cs
- TileBrush.cs
- StyleCollection.cs
- RowCache.cs
- ResourceReferenceExpression.cs
- CheckBoxFlatAdapter.cs
- UnionExpr.cs
- ExtensionCollection.cs
- DefaultSection.cs
- ProxyWebPart.cs
- UICuesEvent.cs
- DrawingServices.cs
- ConcurrentStack.cs
- WsatTransactionFormatter.cs
- SoapEnumAttribute.cs
- CroppedBitmap.cs
- DataGridViewDataErrorEventArgs.cs
- SymbolMethod.cs
- FormsIdentity.cs
- CopyCodeAction.cs
- Window.cs
- DockingAttribute.cs
- ObjectViewFactory.cs
- MethodBuilderInstantiation.cs
- DirectionalLight.cs
- MexHttpBindingElement.cs
- StringValueSerializer.cs
- Scheduler.cs
- ConsumerConnectionPoint.cs
- QuotedStringFormatReader.cs
- WebBrowserSiteBase.cs
- DataTableMappingCollection.cs
- Int32CAMarshaler.cs
- DropShadowBitmapEffect.cs
- MultiPageTextView.cs
- TPLETWProvider.cs
- UndirectedGraph.cs
- WindowsIdentity.cs
- cookiecollection.cs
- InputDevice.cs
- CompilerErrorCollection.cs
- DataSourceCacheDurationConverter.cs
- PerformanceCountersElement.cs
- QuaternionConverter.cs
- StrongNameHelpers.cs
- EncoderParameter.cs
- PropertyValueChangedEvent.cs
- ModuleBuilder.cs
- SetStoryboardSpeedRatio.cs
- InteropAutomationProvider.cs
- BinaryObjectReader.cs
- FileEnumerator.cs