Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Xml / System / Xml / Core / SecureStringHasher.cs / 1305376 / 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; } #if false // This is here only for debugging of hashing issues public SecureStringHasher( int hashCodeRandomizer ) { this.hashCodeRandomizer = hashCodeRandomizer; } #endif 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FtpWebResponse.cs
- XmlMemberMapping.cs
- coordinatorfactory.cs
- StylusTip.cs
- PermissionToken.cs
- DetailsViewUpdateEventArgs.cs
- ListGeneralPage.cs
- IfElseDesigner.xaml.cs
- ResolveRequestResponseAsyncResult.cs
- ServiceObjectContainer.cs
- Array.cs
- Int32Storage.cs
- MobileControlPersister.cs
- UpnEndpointIdentity.cs
- ZoomingMessageFilter.cs
- MdiWindowListItemConverter.cs
- EditCommandColumn.cs
- FirstMatchCodeGroup.cs
- FamilyMap.cs
- BufferedMessageWriter.cs
- ImageKeyConverter.cs
- ControlPaint.cs
- basecomparevalidator.cs
- BooleanFacetDescriptionElement.cs
- AnnotationResource.cs
- FontConverter.cs
- InternalDispatchObject.cs
- XmlAttribute.cs
- TextPattern.cs
- EtwTrace.cs
- TogglePattern.cs
- TableAdapterManagerHelper.cs
- PropertyPathWorker.cs
- WorkflowDesigner.cs
- DefaultBinder.cs
- Rules.cs
- CodeIndexerExpression.cs
- Preprocessor.cs
- LookupBindingPropertiesAttribute.cs
- ResourceReader.cs
- RelationshipFixer.cs
- ObjectDataSource.cs
- _SafeNetHandles.cs
- SafeIUnknown.cs
- BinHexEncoder.cs
- XPathAncestorQuery.cs
- Visual3DCollection.cs
- WindowsAuthenticationEventArgs.cs
- IPEndPoint.cs
- ServiceMoniker.cs
- EllipseGeometry.cs
- MediaContextNotificationWindow.cs
- HttpStaticObjectsCollectionBase.cs
- AffineTransform3D.cs
- TdsParserSafeHandles.cs
- XamlDesignerSerializationManager.cs
- SaveFileDialog.cs
- WindowsComboBox.cs
- WindowVisualStateTracker.cs
- WebReferencesBuildProvider.cs
- WebRequest.cs
- CustomTypeDescriptor.cs
- PointAnimationUsingPath.cs
- ProfileService.cs
- BadImageFormatException.cs
- XmlArrayItemAttributes.cs
- BrowserTree.cs
- CodeObjectCreateExpression.cs
- InputManager.cs
- XmlSchemaSimpleContent.cs
- HitTestWithGeometryDrawingContextWalker.cs
- SwitchElementsCollection.cs
- ArcSegment.cs
- SystemTcpStatistics.cs
- indexingfiltermarshaler.cs
- CheckBox.cs
- DataChangedEventManager.cs
- StringSource.cs
- InputMethodStateTypeInfo.cs
- XmlObjectSerializerContext.cs
- SqlDataSourceCommandEventArgs.cs
- BamlBinaryWriter.cs
- ControlAdapter.cs
- ProgressPage.cs
- Table.cs
- Material.cs
- WebPartManagerInternals.cs
- OutputScopeManager.cs
- ChangePassword.cs
- Pkcs9Attribute.cs
- SqlDelegatedTransaction.cs
- StatusBarDrawItemEvent.cs
- HtmlControl.cs
- Update.cs
- HttpCacheVary.cs
- BCLDebug.cs
- Adorner.cs
- LogReserveAndAppendState.cs
- XmlSchemaInfo.cs
- BulletDecorator.cs