Code:
/ FXUpdate3074 / FXUpdate3074 / 1.1 / untmp / whidbey / QFE / ndp / clr / src / BCL / System / Security / Cryptography / SafeCryptoHandles.cs / 1 / SafeCryptoHandles.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== // // SafeCryptoHandles.cs // namespace System.Security.Cryptography { using System.Runtime.InteropServices; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using Microsoft.Win32.SafeHandles; // Since we need sometimes to delete the key container created in the // context of the CSP, the handle used in this class is actually a pointer // to a CRYPT_PROV_CTX unmanaged structure defined in COMCryptography.h internal sealed class SafeProvHandle : SafeHandleZeroOrMinusOneIsInvalid { // 0 is an Invalid Handle private SafeProvHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeProvHandle InvalidHandle { get { return new SafeProvHandle(IntPtr.Zero); } } // This method handles the case where pProvCtx == NULL [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] // The handle here is actually a pointer to a CRYPT_PROV_CTX unmanaged structure private static extern void _FreeCSP(IntPtr pProvCtx); override protected bool ReleaseHandle() { _FreeCSP(handle); return true; } } // Since we need to delete the key handle before the provider is released // we need to actually hold a pointer to a CRYPT_KEY_CTX unmanaged structure // whose destructor decrements a refCount. Only when the provider refCount is 0 // it is deleted. This way, we loose a race in the internal sealed class SafeKeyHandle : SafeHandleZeroOrMinusOneIsInvalid { // 0 is an Invalid Handle private SafeKeyHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeKeyHandle InvalidHandle { get { return new SafeKeyHandle(IntPtr.Zero); } } [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] // The handle here is actually a pointer to a CRYPT_KEY_CTX unmanaged structure private static extern void _FreeHKey(IntPtr pKeyCtx); override protected bool ReleaseHandle() { _FreeHKey(handle); return true; } } internal sealed class SafeHashHandle : SafeHandleZeroOrMinusOneIsInvalid { // 0 is an Invalid Handle private SafeHashHandle(IntPtr handle) : base (true) { SetHandle(handle); } internal static SafeHashHandle InvalidHandle { get { return new SafeHashHandle(IntPtr.Zero); } } [MethodImplAttribute(MethodImplOptions.InternalCall)] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] // The handle here is actually a pointer to a CRYPT_HASH_CTX unmanaged structure private static extern void _FreeHash(IntPtr pHashCtx); override protected bool ReleaseHandle() { _FreeHash(handle); return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- MobileControlsSection.cs
- Camera.cs
- HtmlSelect.cs
- DesignTable.cs
- SqlBuffer.cs
- DivideByZeroException.cs
- Ipv6Element.cs
- AutomationElement.cs
- _SSPISessionCache.cs
- SemanticResultValue.cs
- ChtmlTextBoxAdapter.cs
- DataGridClipboardHelper.cs
- reliableinputsessionchannel.cs
- InvokeProviderWrapper.cs
- DataGridViewTextBoxColumn.cs
- ResourceFallbackManager.cs
- Substitution.cs
- CompositeControl.cs
- DBBindings.cs
- AttributeParameterInfo.cs
- XmlReturnWriter.cs
- AssemblyCacheEntry.cs
- SessionParameter.cs
- XmlEncApr2001.cs
- ButtonAutomationPeer.cs
- DiffuseMaterial.cs
- SafeNativeMemoryHandle.cs
- SqlTrackingWorkflowInstance.cs
- COM2ExtendedUITypeEditor.cs
- SRGSCompiler.cs
- XmlAnyElementAttribute.cs
- SocketInformation.cs
- TrackBar.cs
- BasicKeyConstraint.cs
- BulletedList.cs
- SqlException.cs
- XPathAxisIterator.cs
- DbConnectionStringBuilder.cs
- XsltException.cs
- SqlProvider.cs
- TextReader.cs
- QuaternionConverter.cs
- SkipStoryboardToFill.cs
- NameValueConfigurationCollection.cs
- DuplicateMessageDetector.cs
- RepeatInfo.cs
- PeerCollaboration.cs
- BrowserTree.cs
- DllNotFoundException.cs
- SqlSupersetValidator.cs
- RMPublishingDialog.cs
- DataObjectEventArgs.cs
- TypedTableGenerator.cs
- ExpressionConverter.cs
- PersonalizationStateInfo.cs
- MsmqInputChannelBase.cs
- BlockCollection.cs
- IPEndPoint.cs
- Control.cs
- BitmapPalette.cs
- DbgCompiler.cs
- EntityTransaction.cs
- OleDbRowUpdatedEvent.cs
- DataGridViewCheckBoxCell.cs
- FontFamilyIdentifier.cs
- FileChangesMonitor.cs
- CellPartitioner.cs
- BindingGroup.cs
- HttpDebugHandler.cs
- XmlSchemaAnnotated.cs
- NaturalLanguageHyphenator.cs
- WebPartHelpVerb.cs
- TransactionInformation.cs
- Profiler.cs
- RootProfilePropertySettingsCollection.cs
- PersianCalendar.cs
- DateRangeEvent.cs
- OutputCacheSection.cs
- DataSourceControl.cs
- XmlCountingReader.cs
- _Rfc2616CacheValidators.cs
- XmlSignificantWhitespace.cs
- DefaultMemberAttribute.cs
- AsymmetricAlgorithm.cs
- DataGridViewSelectedCellCollection.cs
- OleDbDataReader.cs
- ServiceInfo.cs
- CollectionEditorDialog.cs
- SQLBytes.cs
- XmlCDATASection.cs
- DesignerDataSchemaClass.cs
- BitmapCacheBrush.cs
- DeploymentSection.cs
- ReferencedType.cs
- TransportationConfigurationTypeInstallComponent.cs
- SchemaTypeEmitter.cs
- FolderLevelBuildProviderCollection.cs
- activationcontext.cs
- GeneralTransform3DCollection.cs
- InputBindingCollection.cs