Code:
/ DotNET / DotNET / 8.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
- WorkflowServiceHost.cs
- WpfXamlType.cs
- MessageQueueConverter.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- nulltextcontainer.cs
- DataFormat.cs
- ISFClipboardData.cs
- HashCodeCombiner.cs
- MenuAdapter.cs
- HtmlButton.cs
- ControlFilterExpression.cs
- SqlUserDefinedTypeAttribute.cs
- PeerNameRecordCollection.cs
- AutoResetEvent.cs
- ColumnMapCopier.cs
- RelationHandler.cs
- XmlAnyAttributeAttribute.cs
- TraceProvider.cs
- SplitterEvent.cs
- RequestResizeEvent.cs
- SelectedDatesCollection.cs
- UnicastIPAddressInformationCollection.cs
- Border.cs
- ProviderSettingsCollection.cs
- COAUTHIDENTITY.cs
- InputScopeNameConverter.cs
- XamlSerializerUtil.cs
- ResXResourceSet.cs
- DeviceOverridableAttribute.cs
- LayoutEngine.cs
- FindResponse.cs
- SymbolTable.cs
- AuthorizationRule.cs
- StdValidatorsAndConverters.cs
- FormatSettings.cs
- DataSourceControlBuilder.cs
- TextDecoration.cs
- EntityDataSourceView.cs
- _BufferOffsetSize.cs
- XamlSerializationHelper.cs
- SafeFileMappingHandle.cs
- DecoderFallback.cs
- InfoCardKeyedHashAlgorithm.cs
- MimeParameter.cs
- SoapSchemaImporter.cs
- HtmlButton.cs
- DictionaryChange.cs
- DeclaredTypeValidator.cs
- XmlSchemaComplexContentRestriction.cs
- DataGridViewColumnStateChangedEventArgs.cs
- ProfilePropertyMetadata.cs
- Documentation.cs
- oledbmetadatacollectionnames.cs
- CountdownEvent.cs
- __ComObject.cs
- TCEAdapterGenerator.cs
- HttpRequest.cs
- InstancePersistenceException.cs
- InvokeMethodActivity.cs
- ipaddressinformationcollection.cs
- WebPartPersonalization.cs
- SqlRewriteScalarSubqueries.cs
- PostBackTrigger.cs
- StylusDownEventArgs.cs
- Currency.cs
- ReadOnlyTernaryTree.cs
- SmiRecordBuffer.cs
- XmlSchemaObjectCollection.cs
- Sentence.cs
- ScheduleChanges.cs
- QueueAccessMode.cs
- Calendar.cs
- XmlWellformedWriterHelpers.cs
- SystemDiagnosticsSection.cs
- EntityDataSourceWrapperPropertyDescriptor.cs
- _ListenerResponseStream.cs
- HttpCacheParams.cs
- Win32NamedPipes.cs
- TreeSet.cs
- DesignerActionListCollection.cs
- QueueProcessor.cs
- SafeRightsManagementQueryHandle.cs
- TrackingValidationObjectDictionary.cs
- WindowInteropHelper.cs
- ContainerParaClient.cs
- BinaryNode.cs
- DynamicDiscoSearcher.cs
- FontUnit.cs
- IPAddressCollection.cs
- DesignerImageAdapter.cs
- PropertyValue.cs
- TextWriterEngine.cs
- UnsafeNativeMethodsPenimc.cs
- CheckBoxList.cs
- IssuanceTokenProviderBase.cs
- UIElementIsland.cs
- versioninfo.cs
- ColumnProvider.cs
- FileDialogPermission.cs
- DesignerOptions.cs