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
- RemoteEndpointMessageProperty.cs
- UnsafeNativeMethodsCLR.cs
- TextParagraphView.cs
- WebPartCancelEventArgs.cs
- TextWriter.cs
- XmlMemberMapping.cs
- SoapElementAttribute.cs
- SoapSchemaExporter.cs
- Figure.cs
- OdbcError.cs
- InstanceNameConverter.cs
- SqlFunctions.cs
- TextRunCache.cs
- PersistChildrenAttribute.cs
- ExceptionAggregator.cs
- Camera.cs
- ScrollEvent.cs
- ScrollViewer.cs
- Math.cs
- PropertyGrid.cs
- TreeViewTemplateSelector.cs
- EnumerableRowCollectionExtensions.cs
- DbTransaction.cs
- PaperSource.cs
- SpellCheck.cs
- HtmlLink.cs
- XmlTypeAttribute.cs
- ThicknessKeyFrameCollection.cs
- ToolStripSystemRenderer.cs
- AggregationMinMaxHelpers.cs
- ColumnResult.cs
- OleDbCommand.cs
- DataRelationPropertyDescriptor.cs
- IncrementalCompileAnalyzer.cs
- Crc32Helper.cs
- URLEditor.cs
- PersistenceTask.cs
- ListViewItemMouseHoverEvent.cs
- ExitEventArgs.cs
- Preprocessor.cs
- DeferredTextReference.cs
- CompilationSection.cs
- ComboBox.cs
- TableLayoutStyle.cs
- Expander.cs
- NullableDoubleMinMaxAggregationOperator.cs
- TemplateFactory.cs
- QueryContext.cs
- WorkflowServiceBuildProvider.cs
- WebPartConnectionCollection.cs
- FaultContractInfo.cs
- CryptoHelper.cs
- BasicViewGenerator.cs
- RadioButtonList.cs
- HMACSHA256.cs
- ExtensionSimplifierMarkupObject.cs
- EdmProviderManifest.cs
- DPCustomTypeDescriptor.cs
- ToolboxItemFilterAttribute.cs
- Parallel.cs
- DataControlPagerLinkButton.cs
- SafePointer.cs
- TreeIterator.cs
- SafeRegistryHandle.cs
- MultipartIdentifier.cs
- GestureRecognitionResult.cs
- HostExecutionContextManager.cs
- RectangleF.cs
- ServiceReference.cs
- SoapInteropTypes.cs
- HttpMethodConstraint.cs
- ContextStack.cs
- QueryOperationResponseOfT.cs
- TdsParserStaticMethods.cs
- BinaryWriter.cs
- SystemTcpStatistics.cs
- Catch.cs
- BaseEntityWrapper.cs
- EncryptedHeader.cs
- PersonalizablePropertyEntry.cs
- ContentTextAutomationPeer.cs
- GridViewCancelEditEventArgs.cs
- ImageDrawing.cs
- XmlCDATASection.cs
- ParamArrayAttribute.cs
- HttpStaticObjectsCollectionWrapper.cs
- MemoryStream.cs
- ToolStripLabel.cs
- StreamHelper.cs
- InitializerFacet.cs
- StateMachine.cs
- DataListItemCollection.cs
- MessagePropertyDescription.cs
- DataGridViewRowPostPaintEventArgs.cs
- HtmlInputText.cs
- WebPartCancelEventArgs.cs
- AutomationPeer.cs
- ClientUtils.cs
- XmlDictionary.cs
- MexHttpBindingCollectionElement.cs