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
- SkewTransform.cs
- InternalPermissions.cs
- PageStatePersister.cs
- TraceSection.cs
- IProvider.cs
- SimpleExpression.cs
- ByteStreamMessageEncodingElement.cs
- ClaimTypeRequirement.cs
- Helper.cs
- clipboard.cs
- TriggerActionCollection.cs
- LocalizationParserHooks.cs
- HtmlTernaryTree.cs
- DelegateCompletionCallbackWrapper.cs
- SemanticKeyElement.cs
- SqlWebEventProvider.cs
- PerformanceCountersElement.cs
- TimeoutException.cs
- XPathExpr.cs
- ActivityExecutor.cs
- EntityDataSourceContextCreatingEventArgs.cs
- MemoryMappedFile.cs
- CapabilitiesSection.cs
- AttachmentService.cs
- SchemaTableColumn.cs
- ParserContext.cs
- WorkflowRuntimeServiceElementCollection.cs
- MarkupCompilePass1.cs
- RevocationPoint.cs
- XmlLoader.cs
- FlowPosition.cs
- _NegoState.cs
- Executor.cs
- TypeSystem.cs
- PropertyNames.cs
- WindowsFormsHostAutomationPeer.cs
- SqlInternalConnection.cs
- FileSystemEventArgs.cs
- _AuthenticationState.cs
- SelectionWordBreaker.cs
- PropertyChangedEventManager.cs
- DependentTransaction.cs
- Binding.cs
- WebRequestModuleElement.cs
- Listbox.cs
- FrameAutomationPeer.cs
- FieldToken.cs
- Quad.cs
- SafePointer.cs
- KeyValuePair.cs
- SourceFileBuildProvider.cs
- InvalidCastException.cs
- TableItemPattern.cs
- ObjectAssociationEndMapping.cs
- AdornerPresentationContext.cs
- VirtualDirectoryMappingCollection.cs
- HtmlImage.cs
- Decorator.cs
- FlowPosition.cs
- cookiecontainer.cs
- MultiAsyncResult.cs
- RuleSet.cs
- HTMLTextWriter.cs
- InputScope.cs
- StorageEntityTypeMapping.cs
- DetailsViewAutoFormat.cs
- BoolLiteral.cs
- ScalarConstant.cs
- Cursors.cs
- PipelineDeploymentState.cs
- ServiceChannelManager.cs
- ZipIOLocalFileDataDescriptor.cs
- MDIClient.cs
- EmbeddedObject.cs
- SvcFileManager.cs
- XmlNavigatorFilter.cs
- DoubleStorage.cs
- AsyncOperation.cs
- HybridWebProxyFinder.cs
- NullRuntimeConfig.cs
- BindingBase.cs
- CodeGotoStatement.cs
- ServiceDeploymentInfo.cs
- GradientBrush.cs
- IndexedString.cs
- SByteStorage.cs
- FunctionDetailsReader.cs
- NeutralResourcesLanguageAttribute.cs
- EntityKey.cs
- PointHitTestResult.cs
- PermissionSetEnumerator.cs
- ResourcePart.cs
- util.cs
- MultipleCopiesCollection.cs
- PasswordRecoveryDesigner.cs
- RegexMatchCollection.cs
- DefaultSerializationProviderAttribute.cs
- VolatileResourceManager.cs
- BulletedListEventArgs.cs
- ReadOnlyDataSourceView.cs