Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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. // //[....] //----------------------------------------------------------------------------- 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DbDataRecord.cs
- PeerContact.cs
- BaseComponentEditor.cs
- TickBar.cs
- FlowDocument.cs
- InheritanceAttribute.cs
- ExternalFile.cs
- UIPermission.cs
- SQLRoleProvider.cs
- Filter.cs
- Types.cs
- AppDomainShutdownMonitor.cs
- FormViewUpdateEventArgs.cs
- SmiMetaDataProperty.cs
- RuntimeHandles.cs
- ProfileGroupSettingsCollection.cs
- FontCacheUtil.cs
- IndexingContentUnit.cs
- DbReferenceCollection.cs
- DataSourceControlBuilder.cs
- KeySplineConverter.cs
- TextServicesManager.cs
- Helpers.cs
- ValueExpressions.cs
- SmiXetterAccessMap.cs
- ResXResourceSet.cs
- EmptyControlCollection.cs
- WebBaseEventKeyComparer.cs
- SrgsRulesCollection.cs
- GZipStream.cs
- AssemblyAttributes.cs
- Inflater.cs
- StrongName.cs
- XmlCharType.cs
- IIS7UserPrincipal.cs
- ContentElement.cs
- FreezableCollection.cs
- FormViewRow.cs
- TextProperties.cs
- GridViewColumnCollectionChangedEventArgs.cs
- XmlSchema.cs
- EventInfo.cs
- SerializerProvider.cs
- CodeObject.cs
- Matrix3D.cs
- GridViewItemAutomationPeer.cs
- FileReader.cs
- BooleanConverter.cs
- Tuple.cs
- EventDrivenDesigner.cs
- BooleanStorage.cs
- Base64Stream.cs
- Script.cs
- ObjectStateEntryDbDataRecord.cs
- XmlSchemaInfo.cs
- XmlSchemaType.cs
- XmlValidatingReaderImpl.cs
- CodeTypeReferenceCollection.cs
- XmlLanguageConverter.cs
- SizeFConverter.cs
- ChameleonKey.cs
- DefaultAssemblyResolver.cs
- PreviewPrintController.cs
- ServiceModelConfigurationSectionGroup.cs
- DataGridToolTip.cs
- EDesignUtil.cs
- CompiledQueryCacheKey.cs
- DataObjectSettingDataEventArgs.cs
- Gdiplus.cs
- FontEditor.cs
- KnownAssemblyEntry.cs
- RequestResizeEvent.cs
- Atom10FormatterFactory.cs
- PartialTrustHelpers.cs
- PathStreamGeometryContext.cs
- XmlQualifiedNameTest.cs
- ResXResourceReader.cs
- XmlImplementation.cs
- Publisher.cs
- DebugInfoExpression.cs
- XsltOutput.cs
- JulianCalendar.cs
- StylusPointPropertyInfo.cs
- CodeAttributeDeclaration.cs
- DecodeHelper.cs
- TypeContext.cs
- ReadOnlyDictionary.cs
- NativeCppClassAttribute.cs
- NavigationService.cs
- WorkflowApplicationException.cs
- QueryCacheManager.cs
- CultureMapper.cs
- _StreamFramer.cs
- MainMenu.cs
- WindowsRichEditRange.cs
- InternalConfigEventArgs.cs
- DataServiceEntityAttribute.cs
- StreamWithDictionary.cs
- TouchDevice.cs
- ButtonBase.cs