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
- SpeechRecognitionEngine.cs
- validation.cs
- TraceShell.cs
- FormViewInsertedEventArgs.cs
- TransformValueSerializer.cs
- MemberDescriptor.cs
- SuppressIldasmAttribute.cs
- InstancePersistenceException.cs
- CrossSiteScriptingValidation.cs
- Assign.cs
- ToolboxComponentsCreatedEventArgs.cs
- DesignerRegionCollection.cs
- ParameterModifier.cs
- XsdBuildProvider.cs
- BindingMemberInfo.cs
- DataSetUtil.cs
- HtmlTernaryTree.cs
- BuildProvider.cs
- EventManager.cs
- DataObjectSettingDataEventArgs.cs
- Material.cs
- PolicyChain.cs
- CaseStatementProjectedSlot.cs
- LoginView.cs
- PageCanvasSize.cs
- OleDbConnection.cs
- CancellationTokenSource.cs
- MetadataArtifactLoaderCompositeResource.cs
- LineBreakRecord.cs
- ElementProxy.cs
- ChannelBase.cs
- GridViewRow.cs
- HostingEnvironmentException.cs
- TypeLoadException.cs
- VisualStyleInformation.cs
- ParserStack.cs
- ReadOnlyCollectionBase.cs
- ErrorCodes.cs
- ConstantCheck.cs
- OrderedHashRepartitionEnumerator.cs
- TrustManagerMoreInformation.cs
- XmlElement.cs
- BatchParser.cs
- SoapSchemaExporter.cs
- InvalidBodyAccessException.cs
- RepeaterItem.cs
- Rotation3DAnimationUsingKeyFrames.cs
- JavaScriptString.cs
- DecoderFallbackWithFailureFlag.cs
- TextCharacters.cs
- XmlChoiceIdentifierAttribute.cs
- GroupJoinQueryOperator.cs
- SerialPinChanges.cs
- InfoCardKeyedHashAlgorithm.cs
- Mappings.cs
- RectAnimationClockResource.cs
- XmlDataSourceView.cs
- XmlSerializerFactory.cs
- LayoutEditorPart.cs
- Table.cs
- DataServiceRequest.cs
- ClipboardProcessor.cs
- XmlParserContext.cs
- WindowShowOrOpenTracker.cs
- XamlTypeMapperSchemaContext.cs
- HttpApplicationStateBase.cs
- EdmError.cs
- SafeViewOfFileHandle.cs
- ManipulationStartedEventArgs.cs
- InheritanceUI.cs
- ServiceHttpModule.cs
- SHA256.cs
- SHA1CryptoServiceProvider.cs
- DataServiceQueryOfT.cs
- AffineTransform3D.cs
- PageTextBox.cs
- EmptyStringExpandableObjectConverter.cs
- MenuScrollingVisibilityConverter.cs
- DataGridViewBindingCompleteEventArgs.cs
- TraceUtility.cs
- BinaryReader.cs
- Shape.cs
- CanonicalFontFamilyReference.cs
- WebPartZone.cs
- StoreContentChangedEventArgs.cs
- ProxyFragment.cs
- LaxModeSecurityHeaderElementInferenceEngine.cs
- TemplateApplicationHelper.cs
- SelectionManager.cs
- HandlerFactoryWrapper.cs
- FixedDocument.cs
- CqlLexer.cs
- ClientFormsAuthenticationMembershipProvider.cs
- ReadOnlyTernaryTree.cs
- TemplateField.cs
- ProfileService.cs
- DataGridViewCellContextMenuStripNeededEventArgs.cs
- PropertyMetadata.cs
- DbConnectionPoolOptions.cs
- UITypeEditor.cs