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
- DynamicDataResources.Designer.cs
- Brush.cs
- WindowsSolidBrush.cs
- RtfFormatStack.cs
- DataObject.cs
- SpeechEvent.cs
- Wildcard.cs
- ContextStack.cs
- SymbolPair.cs
- HttpBufferlessInputStream.cs
- SqlRowUpdatedEvent.cs
- ShutDownListener.cs
- ColorInterpolationModeValidation.cs
- TraceSection.cs
- OdbcTransaction.cs
- OutgoingWebResponseContext.cs
- DataGridViewCellStyleChangedEventArgs.cs
- ListViewSortEventArgs.cs
- InputProcessorProfiles.cs
- VBCodeProvider.cs
- ProxyGenerator.cs
- DataSet.cs
- ElementHost.cs
- Propagator.JoinPropagator.cs
- ProcessThreadCollection.cs
- XmlLangPropertyAttribute.cs
- TextRunTypographyProperties.cs
- FormsIdentity.cs
- PropertyIDSet.cs
- LoginViewDesigner.cs
- MultipleViewProviderWrapper.cs
- Splitter.cs
- ReferenceService.cs
- HandleCollector.cs
- HelpEvent.cs
- LocalizationComments.cs
- Point3DCollection.cs
- ToolStripOverflow.cs
- RuleElement.cs
- log.cs
- SqlConnectionManager.cs
- _FtpDataStream.cs
- HostProtectionPermission.cs
- ExpressionTable.cs
- RoleExceptions.cs
- AsyncResult.cs
- StringComparer.cs
- EntityDataSourceMemberPath.cs
- ListSortDescriptionCollection.cs
- SafeSystemMetrics.cs
- Clock.cs
- QueryOperationResponseOfT.cs
- ConfigurationManagerInternal.cs
- MultiSelectRootGridEntry.cs
- RootBrowserWindow.cs
- DataGridViewRowStateChangedEventArgs.cs
- QilXmlReader.cs
- MailMessageEventArgs.cs
- DBPropSet.cs
- Rule.cs
- PingOptions.cs
- XmlBinaryReaderSession.cs
- MethodRental.cs
- EncoderReplacementFallback.cs
- DocumentScope.cs
- WorkflowDebuggerSteppingAttribute.cs
- HttpChannelBindingToken.cs
- CompilerScope.Storage.cs
- Pair.cs
- RegexTree.cs
- FaultFormatter.cs
- HttpBufferlessInputStream.cs
- SimpleTypeResolver.cs
- BehaviorDragDropEventArgs.cs
- WindowsListViewGroupSubsetLink.cs
- InvalidFilterCriteriaException.cs
- SvcMapFile.cs
- PageHandlerFactory.cs
- WebEvents.cs
- DataSourceNameHandler.cs
- CustomErrorsSection.cs
- versioninfo.cs
- ChtmlImageAdapter.cs
- Encoding.cs
- HtmlDocument.cs
- FormattedTextSymbols.cs
- GestureRecognizer.cs
- CmsUtils.cs
- ColumnCollection.cs
- HttpStreamFormatter.cs
- SQLDateTime.cs
- WindowsStatic.cs
- ExtensionElement.cs
- DataGridItem.cs
- Crc32.cs
- FragmentQueryKB.cs
- DataSourceControlBuilder.cs
- SystemIcmpV4Statistics.cs
- SettingsPropertyNotFoundException.cs
- CachedBitmap.cs