Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Xml / System / Xml / Core / SecureStringHasher.cs / 1 / SecureStringHasher.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //[....] //----------------------------------------------------------------------------- using System; using System.Collections.Generic; namespace System.Xml { // SecureStringHasher is a hash code provider for strings. The hash codes calculation starts with a seed (hasCodeRandomizer) which is usually // different for each instance of SecureStringHasher. Since the hash code depend on the seed, the chance of hashtable DoS attack in case when // someone passes in lots of strings that hash to the same hash code is greatly reduced. // The SecureStringHasher implements IEqualityComparer for strings and therefore can be used in generic IDictionary. internal class SecureStringHasher : IEqualityComparer{ int hashCodeRandomizer; public SecureStringHasher() { this.hashCodeRandomizer = Environment.TickCount; } public SecureStringHasher( int hashCodeRandomizer ) { this.hashCodeRandomizer = hashCodeRandomizer; } public int Compare( String x, String y ) { return String.Compare(x, y, StringComparison.Ordinal); } public bool Equals( String x, String y ) { return String.Equals( x, y, StringComparison.Ordinal ); } public int GetHashCode( String key ) { int hashCode = hashCodeRandomizer; // use key.Length to eliminate the rangecheck for ( int i = 0; i < key.Length; i++ ) { hashCode += ( hashCode << 7 ) ^ key[i]; } // mix it a bit more hashCode -= hashCode >> 17; hashCode -= hashCode >> 11; hashCode -= hashCode >> 5; return hashCode; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ListItemConverter.cs
- BlurBitmapEffect.cs
- DPAPIProtectedConfigurationProvider.cs
- FixedPageAutomationPeer.cs
- MemoryMappedViewAccessor.cs
- UriExt.cs
- RangeValidator.cs
- JournalEntryStack.cs
- Switch.cs
- QilList.cs
- XmlWriterDelegator.cs
- CompletedAsyncResult.cs
- DragCompletedEventArgs.cs
- XmlMapping.cs
- RegisteredArrayDeclaration.cs
- ControlUtil.cs
- BaseResourcesBuildProvider.cs
- SchemaTypeEmitter.cs
- DataGrid.cs
- BindingBase.cs
- HttpMethodAttribute.cs
- XamlValidatingReader.cs
- DrawingGroupDrawingContext.cs
- GenerateScriptTypeAttribute.cs
- HtmlTextArea.cs
- EventsTab.cs
- ToolStrip.cs
- PasswordRecoveryAutoFormat.cs
- NetSectionGroup.cs
- Converter.cs
- ThemeInfoAttribute.cs
- CombinedGeometry.cs
- BaseTreeIterator.cs
- Equal.cs
- DataGridAutoFormat.cs
- MatrixIndependentAnimationStorage.cs
- ServiceBusyException.cs
- TemplateControlParser.cs
- MetadataSource.cs
- HttpBrowserCapabilitiesWrapper.cs
- LiteralControl.cs
- QueryInterceptorAttribute.cs
- AspProxy.cs
- NumericUpDown.cs
- ServiceProviders.cs
- Pool.cs
- DataGridViewRowEventArgs.cs
- CornerRadius.cs
- TypeBuilder.cs
- StrokeRenderer.cs
- Thread.cs
- SQLInt64Storage.cs
- CollectionViewGroup.cs
- RadioButtonFlatAdapter.cs
- DataGridDetailsPresenter.cs
- TreeWalkHelper.cs
- JsonFormatGeneratorStatics.cs
- SpecialFolderEnumConverter.cs
- PolicyStatement.cs
- GeneralTransform3D.cs
- FlowDocumentView.cs
- VirtualizingStackPanel.cs
- ACL.cs
- TransferRequestHandler.cs
- KeyValuePair.cs
- HitTestWithGeometryDrawingContextWalker.cs
- ControlParameter.cs
- SafeNativeMethods.cs
- Int16Animation.cs
- TemplateContainer.cs
- TypeUtils.cs
- BookmarkList.cs
- DockProviderWrapper.cs
- HyperLinkField.cs
- unsafenativemethodstextservices.cs
- GradientStop.cs
- SqlConnectionStringBuilder.cs
- DllNotFoundException.cs
- Timeline.cs
- SqlDataAdapter.cs
- Padding.cs
- SqlDataAdapter.cs
- MaterialGroup.cs
- Trace.cs
- TableLayoutSettingsTypeConverter.cs
- DebuggerAttributes.cs
- FormCollection.cs
- EmptyControlCollection.cs
- DataGridCommandEventArgs.cs
- TraceEventCache.cs
- Int32AnimationBase.cs
- Pens.cs
- ReadOnlyActivityGlyph.cs
- EventToken.cs
- X509ScopedServiceCertificateElement.cs
- CodeObject.cs
- UpdateCommand.cs
- TextFormatterContext.cs
- CheckBoxAutomationPeer.cs
- ValueExpressions.cs