Code:
/ 4.0 / 4.0 / 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. //------------------------------------------------------------------------------ // // 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
- DataGridViewButtonColumn.cs
- XmlRawWriter.cs
- PageThemeBuildProvider.cs
- XPathMessageFilter.cs
- PersistenceTypeAttribute.cs
- HtmlInputRadioButton.cs
- ConfigurationValues.cs
- CqlWriter.cs
- CompilerGlobalScopeAttribute.cs
- Drawing.cs
- Command.cs
- CompressEmulationStream.cs
- BrowsableAttribute.cs
- ChtmlFormAdapter.cs
- FileIOPermission.cs
- HostDesigntimeLicenseContext.cs
- Tokenizer.cs
- LogLogRecordHeader.cs
- ToolstripProfessionalRenderer.cs
- CodeAttachEventStatement.cs
- _FtpDataStream.cs
- LinqToSqlWrapper.cs
- Point4D.cs
- InkCollectionBehavior.cs
- AxisAngleRotation3D.cs
- Pointer.cs
- XmlLinkedNode.cs
- DaylightTime.cs
- Selector.cs
- StatusBarAutomationPeer.cs
- MouseGesture.cs
- IndicCharClassifier.cs
- InheritablePropertyChangeInfo.cs
- BasicViewGenerator.cs
- AssociatedControlConverter.cs
- XmlSerializerNamespaces.cs
- SeverityFilter.cs
- EmptyCollection.cs
- FeatureSupport.cs
- ObjectViewFactory.cs
- MediaPlayer.cs
- DataRecord.cs
- _SSPISessionCache.cs
- COM2PropertyPageUITypeConverter.cs
- FastPropertyAccessor.cs
- PropertyTabChangedEvent.cs
- EventData.cs
- DataObjectPastingEventArgs.cs
- WebException.cs
- DataFormats.cs
- TypeElement.cs
- DataMisalignedException.cs
- TextServicesCompartmentContext.cs
- XamlFrame.cs
- ExpressionPrefixAttribute.cs
- PathFigureCollectionConverter.cs
- ZoneMembershipCondition.cs
- DefaultExpression.cs
- _ProxyChain.cs
- RadioButtonPopupAdapter.cs
- PreservationFileWriter.cs
- PropertyReferenceSerializer.cs
- IntPtr.cs
- CapacityStreamGeometryContext.cs
- MultipleCopiesCollection.cs
- MemoryRecordBuffer.cs
- PnrpPermission.cs
- IteratorDescriptor.cs
- ComponentResourceKeyConverter.cs
- AccessDataSourceWizardForm.cs
- RuleInfoComparer.cs
- TypeUnloadedException.cs
- UpdateException.cs
- _SslStream.cs
- Paragraph.cs
- HttpCachePolicy.cs
- ExtendedProperty.cs
- NumberFormatter.cs
- GiveFeedbackEvent.cs
- ListDesigner.cs
- Propagator.JoinPropagator.cs
- CommentEmitter.cs
- ActivitySurrogateSelector.cs
- DataGridViewAccessibleObject.cs
- ListViewDeletedEventArgs.cs
- DefaultIfEmptyQueryOperator.cs
- HMACRIPEMD160.cs
- Menu.cs
- ReflectTypeDescriptionProvider.cs
- SQLDouble.cs
- EtwProvider.cs
- FormatterConverter.cs
- InputBinder.cs
- HwndTarget.cs
- DefaultPrintController.cs
- SharedStatics.cs
- DataTable.cs
- ErrorsHelper.cs
- RegexCharClass.cs
- TypefaceCollection.cs