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
- Privilege.cs
- BooleanKeyFrameCollection.cs
- XmlSchemaObject.cs
- HtmlInputPassword.cs
- DataServiceRequestOfT.cs
- ErrorLog.cs
- SerializationAttributes.cs
- SoapIncludeAttribute.cs
- SectionXmlInfo.cs
- compensatingcollection.cs
- SystemUdpStatistics.cs
- HighlightComponent.cs
- AsnEncodedData.cs
- EncryptedType.cs
- TextBoxRenderer.cs
- ToolStripEditorManager.cs
- BuilderPropertyEntry.cs
- ToolStripContentPanel.cs
- DataGridViewCellConverter.cs
- NavigationService.cs
- XmlSchemaCompilationSettings.cs
- BitmapEffectState.cs
- Utils.cs
- XmlQueryTypeFactory.cs
- SqlConnectionPoolGroupProviderInfo.cs
- GeometryHitTestParameters.cs
- initElementDictionary.cs
- LingerOption.cs
- PolicyException.cs
- SecurityContext.cs
- RequestTimeoutManager.cs
- ClaimTypeElement.cs
- _ScatterGatherBuffers.cs
- ListSortDescription.cs
- SmtpNegotiateAuthenticationModule.cs
- SizeConverter.cs
- HttpHeaderCollection.cs
- ProxyFragment.cs
- ArgumentException.cs
- XmlEntityReference.cs
- EnumerableWrapperWeakToStrong.cs
- WebCategoryAttribute.cs
- WebServicesInteroperability.cs
- JoinTreeSlot.cs
- _AutoWebProxyScriptEngine.cs
- TextTreeTextNode.cs
- PageStatePersister.cs
- EncryptedKey.cs
- XmlElementAttribute.cs
- DelegateArgument.cs
- Effect.cs
- LogicalExpressionEditor.cs
- AcceptorSessionSymmetricTransportSecurityProtocol.cs
- CodeCatchClause.cs
- ArrayElementGridEntry.cs
- TextRange.cs
- HashSetDebugView.cs
- FormsAuthenticationTicket.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- CompiledIdentityConstraint.cs
- TCPClient.cs
- DbConnectionClosed.cs
- Pair.cs
- PnrpPermission.cs
- NgenServicingAttributes.cs
- DataRelationCollection.cs
- X509Chain.cs
- DependencyObjectType.cs
- WinFormsUtils.cs
- CodeTypeParameterCollection.cs
- SqlNotificationEventArgs.cs
- _LocalDataStore.cs
- ItemsChangedEventArgs.cs
- SubpageParagraph.cs
- ContentType.cs
- BitSet.cs
- GradientBrush.cs
- SqlConnectionString.cs
- ConstraintCollection.cs
- ReflectionUtil.cs
- FlowDocumentPage.cs
- X509CertificateCollection.cs
- XsltCompileContext.cs
- XslVisitor.cs
- SQLSingleStorage.cs
- SystemEvents.cs
- FileDataSourceCache.cs
- DispatcherHookEventArgs.cs
- HotSpot.cs
- WebPartTransformer.cs
- DynamicControlParameter.cs
- NativeMethodsOther.cs
- CriticalExceptions.cs
- ConnectionStringsSection.cs
- KeyInstance.cs
- Content.cs
- TransformBlockRequest.cs
- ToolStripOverflowButton.cs
- regiisutil.cs
- ToolStripRenderer.cs