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
- __TransparentProxy.cs
- SchemaCollectionPreprocessor.cs
- InkSerializer.cs
- BaseParagraph.cs
- glyphs.cs
- StyleBamlRecordReader.cs
- TimelineCollection.cs
- TypeRestriction.cs
- SafeWaitHandle.cs
- MostlySingletonList.cs
- WebPartConnectionsCloseVerb.cs
- RijndaelCryptoServiceProvider.cs
- Quaternion.cs
- DockingAttribute.cs
- HttpFileCollection.cs
- SqlConnectionHelper.cs
- WebPartCatalogCloseVerb.cs
- GCHandleCookieTable.cs
- LiteralTextParser.cs
- PackWebResponse.cs
- ConcurrentStack.cs
- InputProviderSite.cs
- RelatedCurrencyManager.cs
- IgnoreFlushAndCloseStream.cs
- BindingExpressionUncommonField.cs
- LocatorPartList.cs
- QueueAccessMode.cs
- ReadWriteSpinLock.cs
- Expr.cs
- mediapermission.cs
- Triangle.cs
- MimeMapping.cs
- StringWriter.cs
- CustomValidator.cs
- Resources.Designer.cs
- XmlBoundElement.cs
- EtwTrace.cs
- RSAPKCS1SignatureDeformatter.cs
- DeclarativeCatalogPart.cs
- IItemProperties.cs
- _OverlappedAsyncResult.cs
- IxmlLineInfo.cs
- DeviceContexts.cs
- XmlTextEncoder.cs
- ListViewDeleteEventArgs.cs
- UiaCoreApi.cs
- initElementDictionary.cs
- Enum.cs
- TypeSystemHelpers.cs
- StyleCollection.cs
- ItemDragEvent.cs
- InsufficientMemoryException.cs
- WorkflowHostingResponseContext.cs
- DataGridViewDataConnection.cs
- XPathCompileException.cs
- XamlTemplateSerializer.cs
- InfoCardArgumentException.cs
- DataGridViewColumnCollection.cs
- DataGridViewRowCancelEventArgs.cs
- StoragePropertyMapping.cs
- Nullable.cs
- Timeline.cs
- Size.cs
- WebPartConnectionsConnectVerb.cs
- DisableDpiAwarenessAttribute.cs
- BinaryObjectReader.cs
- ColorTransformHelper.cs
- ProgressBarAutomationPeer.cs
- AccessDataSourceView.cs
- HttpPostClientProtocol.cs
- AstNode.cs
- InkCanvasSelection.cs
- HostedBindingBehavior.cs
- ThreadAttributes.cs
- AdornerDecorator.cs
- BindingMemberInfo.cs
- StringExpressionSet.cs
- CmsInterop.cs
- OdbcConnection.cs
- FacetChecker.cs
- ScrollableControl.cs
- BindingContext.cs
- PathGradientBrush.cs
- CodeDOMProvider.cs
- CodeIndexerExpression.cs
- EntityDataSourceStatementEditorForm.cs
- SqlFunctionAttribute.cs
- GeneratedContractType.cs
- LambdaExpression.cs
- SystemIPAddressInformation.cs
- UInt32Storage.cs
- DataSourceCache.cs
- EventItfInfo.cs
- PolygonHotSpot.cs
- DataSourceCollectionBase.cs
- precedingquery.cs
- InternalBufferManager.cs
- UTF7Encoding.cs
- FloatAverageAggregationOperator.cs
- WebPartHelpVerb.cs