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
- DateBoldEvent.cs
- XamlParser.cs
- WebPartConnectionsCancelEventArgs.cs
- X509Certificate2Collection.cs
- MonitoringDescriptionAttribute.cs
- ConcatQueryOperator.cs
- ThemeDirectoryCompiler.cs
- ExtendedTransformFactory.cs
- RuleInfoComparer.cs
- InputBuffer.cs
- Cursors.cs
- SelectionUIHandler.cs
- ProgressBarBrushConverter.cs
- X509CertificateValidator.cs
- PagesSection.cs
- AutoGeneratedFieldProperties.cs
- AsyncContentLoadedEventArgs.cs
- SecurityBindingElement.cs
- PropertyTabAttribute.cs
- ObjectDataSource.cs
- CompositionTarget.cs
- AutomationProperties.cs
- ShimAsPublicXamlType.cs
- TableLayoutSettingsTypeConverter.cs
- DispatchChannelSink.cs
- JsonFormatWriterGenerator.cs
- RightsManagementEncryptionTransform.cs
- VsPropertyGrid.cs
- SystemInfo.cs
- FieldAccessException.cs
- PolyBezierSegmentFigureLogic.cs
- DrawListViewSubItemEventArgs.cs
- PackagePartCollection.cs
- XmlCharType.cs
- HttpWriter.cs
- WebServiceParameterData.cs
- ButtonBaseAdapter.cs
- GridViewUpdateEventArgs.cs
- RelativeSource.cs
- CqlIdentifiers.cs
- CoTaskMemHandle.cs
- TCEAdapterGenerator.cs
- CodeTypeMember.cs
- AdPostCacheSubstitution.cs
- CompletionBookmark.cs
- FrameworkRichTextComposition.cs
- WebConfigurationFileMap.cs
- Profiler.cs
- OracleException.cs
- FileNotFoundException.cs
- MulticastIPAddressInformationCollection.cs
- PageAsyncTaskManager.cs
- exports.cs
- ExpressionTextBox.xaml.cs
- FileDialog_Vista_Interop.cs
- TableLayoutSettingsTypeConverter.cs
- WebPartConnectionsEventArgs.cs
- ByteArrayHelperWithString.cs
- BitmapEffectOutputConnector.cs
- EventLogEntry.cs
- Frame.cs
- FolderBrowserDialog.cs
- ConnectionStringEditor.cs
- OrderedEnumerableRowCollection.cs
- GridViewUpdatedEventArgs.cs
- AutomationFocusChangedEventArgs.cs
- OpenTypeCommon.cs
- URLAttribute.cs
- CompositeActivityTypeDescriptorProvider.cs
- FileDetails.cs
- BuildResultCache.cs
- RuntimeIdentifierPropertyAttribute.cs
- BasicCellRelation.cs
- TransactionTraceIdentifier.cs
- Byte.cs
- GeneralTransform3D.cs
- EncoderParameters.cs
- QueryPageSettingsEventArgs.cs
- PrePrepareMethodAttribute.cs
- ObjectViewQueryResultData.cs
- RichTextBoxAutomationPeer.cs
- TextTreeInsertElementUndoUnit.cs
- CustomSignedXml.cs
- AssemblySettingAttributes.cs
- XPathConvert.cs
- SafePEFileHandle.cs
- Debug.cs
- Filter.cs
- AbsoluteQuery.cs
- AnnotationComponentChooser.cs
- AspNetPartialTrustHelpers.cs
- LambdaCompiler.Address.cs
- DbProviderServices.cs
- SecureStringHasher.cs
- FunctionNode.cs
- AlphabetConverter.cs
- entityreference_tresulttype.cs
- DataSvcMapFile.cs
- CommandLibraryHelper.cs
- EntityProxyTypeInfo.cs