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
- RowType.cs
- LongValidatorAttribute.cs
- x509store.cs
- ContextProperty.cs
- DataServiceEntityAttribute.cs
- HyperLinkField.cs
- DocumentCollection.cs
- bindurihelper.cs
- XmlBaseWriter.cs
- TableAdapterManagerHelper.cs
- TableLayoutPanelCodeDomSerializer.cs
- CredentialCache.cs
- XmlLanguage.cs
- FrameworkElement.cs
- XmlRawWriter.cs
- InstanceNotFoundException.cs
- DrawingBrush.cs
- ReverseInheritProperty.cs
- ViewValidator.cs
- EffectiveValueEntry.cs
- __TransparentProxy.cs
- CalendarItem.cs
- BlockCollection.cs
- ChtmlFormAdapter.cs
- SafeMarshalContext.cs
- MD5.cs
- ClientTargetCollection.cs
- CapabilitiesPattern.cs
- DateTimeStorage.cs
- UpdateTracker.cs
- PermissionSetTriple.cs
- Comparer.cs
- ChangeBlockUndoRecord.cs
- webclient.cs
- MemberPath.cs
- SecurityPermission.cs
- TextMessageEncoder.cs
- DataDocumentXPathNavigator.cs
- IProvider.cs
- TemplateKeyConverter.cs
- URLIdentityPermission.cs
- SafeSecurityHandles.cs
- CustomSignedXml.cs
- TextSchema.cs
- SQLInt16Storage.cs
- ActivityTypeResolver.xaml.cs
- QilNode.cs
- PeerSecurityHelpers.cs
- DataGridViewCell.cs
- BuildManagerHost.cs
- MenuCommand.cs
- SchemaNames.cs
- ObjectTypeMapping.cs
- BCLDebug.cs
- HtmlControl.cs
- MarshalDirectiveException.cs
- ZeroOpNode.cs
- TextAdaptor.cs
- InternalBufferOverflowException.cs
- DataTable.cs
- thaishape.cs
- CompilerParameters.cs
- TextSelection.cs
- StylusPointPropertyId.cs
- SqlClientMetaDataCollectionNames.cs
- RemoveStoryboard.cs
- HttpVersion.cs
- ThemeConfigurationDialog.cs
- ToolBarOverflowPanel.cs
- DateTimeFormat.cs
- DatePicker.cs
- ClientScriptManagerWrapper.cs
- COM2Properties.cs
- XmlReader.cs
- GridViewColumnHeader.cs
- PortCache.cs
- ContainerParagraph.cs
- PatternMatcher.cs
- WebPartConnectionsCancelEventArgs.cs
- ImportException.cs
- UIElementPropertyUndoUnit.cs
- HtmlShimManager.cs
- MarkupProperty.cs
- ModelPerspective.cs
- QEncodedStream.cs
- MappingSource.cs
- AppLevelCompilationSectionCache.cs
- CompilationSection.cs
- _Win32.cs
- OdbcPermission.cs
- HitTestWithGeometryDrawingContextWalker.cs
- WebPartZoneCollection.cs
- DataControlField.cs
- TrackingParameters.cs
- XmlTextEncoder.cs
- DirtyTextRange.cs
- HttpUnhandledOperationInvoker.cs
- ControlBuilderAttribute.cs
- Constants.cs
- TdsRecordBufferSetter.cs