Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ //// 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
- entitydatasourceentitysetnameconverter.cs
- DelimitedListTraceListener.cs
- TemplateAction.cs
- METAHEADER.cs
- StaticExtensionConverter.cs
- BlobPersonalizationState.cs
- BufferedGraphicsContext.cs
- SynchronizingStream.cs
- CacheHelper.cs
- CdpEqualityComparer.cs
- DeclarationUpdate.cs
- HeaderCollection.cs
- Ipv6Element.cs
- _TimerThread.cs
- AsymmetricAlgorithm.cs
- FlowPosition.cs
- Padding.cs
- __FastResourceComparer.cs
- DataGridViewRowCancelEventArgs.cs
- AccessDataSourceView.cs
- CodeTypeReferenceCollection.cs
- ScrollViewer.cs
- ExpressionWriter.cs
- SplitContainer.cs
- InstallerTypeAttribute.cs
- TextTreeTextBlock.cs
- PropertyEmitter.cs
- SQLSingleStorage.cs
- PersonalizationAdministration.cs
- ApplicationGesture.cs
- FileStream.cs
- PrintControllerWithStatusDialog.cs
- CSharpCodeProvider.cs
- RTLAwareMessageBox.cs
- UserInitiatedNavigationPermission.cs
- NativeMethods.cs
- FloatAverageAggregationOperator.cs
- ContextItem.cs
- UshortList2.cs
- PropertyDescriptorComparer.cs
- DataViewManagerListItemTypeDescriptor.cs
- DBParameter.cs
- Debug.cs
- GeneratedContractType.cs
- Walker.cs
- ParameterElementCollection.cs
- XmlSchemaAny.cs
- ScriptingAuthenticationServiceSection.cs
- OleDbRowUpdatedEvent.cs
- BuildProvider.cs
- CompletedAsyncResult.cs
- ValueOfAction.cs
- RuleSetDialog.Designer.cs
- Stack.cs
- RuleInfoComparer.cs
- SharedPerformanceCounter.cs
- HttpStreams.cs
- KeyedCollection.cs
- SqlCacheDependencyDatabaseCollection.cs
- MeasureItemEvent.cs
- HttpListenerRequest.cs
- TreeViewAutomationPeer.cs
- WindowsToolbarItemAsMenuItem.cs
- GridView.cs
- ContainerTracking.cs
- CatalogZoneBase.cs
- ScrollItemProviderWrapper.cs
- PointAnimationClockResource.cs
- BoolLiteral.cs
- COM2ExtendedBrowsingHandler.cs
- SmtpDigestAuthenticationModule.cs
- AxisAngleRotation3D.cs
- ListViewItemEventArgs.cs
- StringUtil.cs
- ToolStripRenderEventArgs.cs
- HttpApplicationFactory.cs
- EventBuilder.cs
- DataObjectFieldAttribute.cs
- EncodingDataItem.cs
- ListenerAdapterBase.cs
- EntityStoreSchemaGenerator.cs
- TableItemStyle.cs
- UnauthorizedWebPart.cs
- TextTabProperties.cs
- PropertyRef.cs
- SelectorItemAutomationPeer.cs
- PhonemeEventArgs.cs
- WebBrowsableAttribute.cs
- MsmqIntegrationMessageProperty.cs
- DocumentEventArgs.cs
- UserControlBuildProvider.cs
- SessionPageStateSection.cs
- DataObjectFieldAttribute.cs
- XPathEmptyIterator.cs
- TransformCollection.cs
- ObjectSelectorEditor.cs
- DataContractSerializerFaultFormatter.cs
- DefaultPropertyAttribute.cs
- WpfXamlLoader.cs
- _AutoWebProxyScriptHelper.cs