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
- UIPermission.cs
- SQLInt16Storage.cs
- PropertyMetadata.cs
- CodeArrayCreateExpression.cs
- MailBnfHelper.cs
- XmlIlVisitor.cs
- CheckBoxField.cs
- WebBrowserHelper.cs
- RenamedEventArgs.cs
- GridItemCollection.cs
- SpeakInfo.cs
- PackageProperties.cs
- MetadataHelper.cs
- UnsafeNativeMethods.cs
- BamlStream.cs
- WebPartConnectionsCancelEventArgs.cs
- BaseTreeIterator.cs
- GroupStyle.cs
- PrefixQName.cs
- HttpResponseWrapper.cs
- CompleteWizardStep.cs
- AgileSafeNativeMemoryHandle.cs
- DurableEnlistmentState.cs
- ResourceKey.cs
- InputMethod.cs
- XmlSchemaValidator.cs
- ParsedAttributeCollection.cs
- XPathMultyIterator.cs
- HostingEnvironment.cs
- FastEncoder.cs
- NotifyInputEventArgs.cs
- PngBitmapEncoder.cs
- RawStylusInput.cs
- TdsEnums.cs
- SqlTypeSystemProvider.cs
- AccessorTable.cs
- SystemIcmpV6Statistics.cs
- ConstNode.cs
- Bitmap.cs
- TreeNodeCollection.cs
- DashStyle.cs
- Pool.cs
- AliasedExpr.cs
- ColorInterpolationModeValidation.cs
- activationcontext.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- StorageEndPropertyMapping.cs
- StatusStrip.cs
- ControlEvent.cs
- SizeAnimationBase.cs
- ObjectListCommandsPage.cs
- Matrix3DConverter.cs
- UnsafePeerToPeerMethods.cs
- BuildManager.cs
- RowUpdatedEventArgs.cs
- TextTreeText.cs
- DeviceContext.cs
- TextEmbeddedObject.cs
- GroupStyle.cs
- ReferenceConverter.cs
- TdsParserStateObject.cs
- MethodBuilderInstantiation.cs
- Int64KeyFrameCollection.cs
- PerformanceCountersElement.cs
- CodeGenerator.cs
- KnownAssembliesSet.cs
- AmbiguousMatchException.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- ProfileBuildProvider.cs
- GroupBoxRenderer.cs
- ImageCreator.cs
- ProfileParameter.cs
- HighContrastHelper.cs
- XPathSelfQuery.cs
- Point3DCollectionValueSerializer.cs
- TimeSpanValidator.cs
- InputLangChangeEvent.cs
- glyphs.cs
- DataViewListener.cs
- DefaultTextStore.cs
- PackageStore.cs
- HttpCapabilitiesBase.cs
- RewritingPass.cs
- ControlBuilderAttribute.cs
- BinaryMessageEncodingBindingElement.cs
- MimeObjectFactory.cs
- TagNameToTypeMapper.cs
- RegionInfo.cs
- X509RawDataKeyIdentifierClause.cs
- XmlUtil.cs
- WhiteSpaceTrimStringConverter.cs
- Visual.cs
- DrawingAttributeSerializer.cs
- XPathParser.cs
- Image.cs
- SerializationAttributes.cs
- WindowsHyperlink.cs
- OleStrCAMarshaler.cs
- ThreadExceptionEvent.cs
- SafePointer.cs