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
- ColumnResizeAdorner.cs
- Calendar.cs
- CounterCreationData.cs
- Image.cs
- Canvas.cs
- View.cs
- Validator.cs
- TextBox.cs
- DataRelationCollection.cs
- UrlParameterReader.cs
- ListControlConvertEventArgs.cs
- BatchParser.cs
- WebRequest.cs
- FaultHandlingFilter.cs
- GenericPrincipal.cs
- ImageBrush.cs
- regiisutil.cs
- StickyNoteAnnotations.cs
- PermissionSet.cs
- MenuItem.cs
- SchemaEntity.cs
- RegexCharClass.cs
- CachedTypeface.cs
- XmlRootAttribute.cs
- ExternalException.cs
- TraceSection.cs
- ADMembershipUser.cs
- RuleSettings.cs
- ToolStripPanelDesigner.cs
- ColumnHeaderConverter.cs
- SynchronizationLockException.cs
- TextRunCache.cs
- PersonalizationProvider.cs
- WindowPatternIdentifiers.cs
- XamlClipboardData.cs
- Light.cs
- ButtonBase.cs
- CustomErrorsSection.cs
- PaintValueEventArgs.cs
- PhysicalAddress.cs
- PeerCollaborationPermission.cs
- UpDownBase.cs
- UnknownWrapper.cs
- CodeBlockBuilder.cs
- InputLanguageManager.cs
- _StreamFramer.cs
- MessageAction.cs
- DataTableMappingCollection.cs
- BuilderInfo.cs
- OLEDB_Util.cs
- XmlSchemaExternal.cs
- TabPage.cs
- SystemNetHelpers.cs
- OrderByQueryOptionExpression.cs
- DataViewManager.cs
- OleDbCommand.cs
- ObjectAnimationUsingKeyFrames.cs
- SqlTrackingService.cs
- PrePrepareMethodAttribute.cs
- NonClientArea.cs
- OracleConnection.cs
- WebConfigurationFileMap.cs
- SQLStringStorage.cs
- EntityDataSourceDataSelectionPanel.designer.cs
- DataChangedEventManager.cs
- Rfc4050KeyFormatter.cs
- RubberbandSelector.cs
- RootBuilder.cs
- PageParser.cs
- CallbackException.cs
- Events.cs
- HandledMouseEvent.cs
- COM2PropertyPageUITypeConverter.cs
- KeyFrames.cs
- FeatureManager.cs
- ElementMarkupObject.cs
- JoinCqlBlock.cs
- DataControlButton.cs
- NativeMethods.cs
- PerformanceCounterPermission.cs
- ThicknessKeyFrameCollection.cs
- HiddenField.cs
- FieldBuilder.cs
- SessionIDManager.cs
- Icon.cs
- EventArgs.cs
- ModifierKeysConverter.cs
- ProtocolsConfigurationHandler.cs
- AsymmetricSignatureFormatter.cs
- EmbossBitmapEffect.cs
- CombinedTcpChannel.cs
- DataError.cs
- FileDialogCustomPlace.cs
- SqlTypeConverter.cs
- UserNameSecurityTokenProvider.cs
- XmlNamespaceMapping.cs
- InfoCardBaseException.cs
- WindowsSolidBrush.cs
- DynamicResourceExtension.cs
- OLEDB_Util.cs