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
- InfoCardRSACryptoProvider.cs
- Icon.cs
- DecoderBestFitFallback.cs
- TextRunCacheImp.cs
- WebContext.cs
- counter.cs
- DeclarativeExpressionConditionDeclaration.cs
- IImplicitResourceProvider.cs
- OdbcConnectionOpen.cs
- Publisher.cs
- Help.cs
- ToolStripDropTargetManager.cs
- CodeRemoveEventStatement.cs
- ObjectDataSourceChooseTypePanel.cs
- BaseComponentEditor.cs
- ACL.cs
- FileStream.cs
- ColumnHeaderCollectionEditor.cs
- SchemaMapping.cs
- ControllableStoryboardAction.cs
- WebPartConnectionCollection.cs
- DataGridViewCellConverter.cs
- TypeSystem.cs
- ViewRendering.cs
- VectorKeyFrameCollection.cs
- ProgressBarAutomationPeer.cs
- DefaultEventAttribute.cs
- MsmqQueue.cs
- CodeMemberProperty.cs
- UrlPath.cs
- HiddenField.cs
- DecimalSumAggregationOperator.cs
- AsyncParams.cs
- ProfileGroupSettingsCollection.cs
- PropertyToken.cs
- Boolean.cs
- HttpResponseInternalWrapper.cs
- XmlSchemaElement.cs
- BinaryUtilClasses.cs
- ManagedIStream.cs
- Query.cs
- DrawingContextWalker.cs
- EditCommandColumn.cs
- LabelLiteral.cs
- ParseElementCollection.cs
- SecurityPermission.cs
- UInt16Storage.cs
- WaitHandle.cs
- CreationContext.cs
- GridViewCancelEditEventArgs.cs
- LayoutUtils.cs
- RoleExceptions.cs
- SecurityPolicySection.cs
- SingleAnimationUsingKeyFrames.cs
- MobileTextWriter.cs
- SecurityPolicySection.cs
- ListViewVirtualItemsSelectionRangeChangedEvent.cs
- DragEventArgs.cs
- DetailsViewModeEventArgs.cs
- ActivityExecutor.cs
- MetadataCache.cs
- DiagnosticTraceRecords.cs
- DefaultObjectSerializer.cs
- SimpleWebHandlerParser.cs
- HyperLinkStyle.cs
- MachineSettingsSection.cs
- DataGridViewColumnConverter.cs
- xml.cs
- LifetimeServices.cs
- TextFormatterImp.cs
- ApplicationSecurityInfo.cs
- WebPartZoneBase.cs
- Monitor.cs
- OracleDateTime.cs
- SqlAggregateChecker.cs
- Duration.cs
- DelegateHelpers.cs
- LocatorBase.cs
- LineGeometry.cs
- _DisconnectOverlappedAsyncResult.cs
- DetailsViewInsertedEventArgs.cs
- XmlLinkedNode.cs
- HttpListenerContext.cs
- DbProviderFactoriesConfigurationHandler.cs
- ListGeneralPage.cs
- CodeIndexerExpression.cs
- ListDictionaryInternal.cs
- VisualTreeUtils.cs
- DataGridViewLinkCell.cs
- SplayTreeNode.cs
- DesignerDeviceConfig.cs
- WindowsAuthenticationModule.cs
- RootAction.cs
- GridViewSortEventArgs.cs
- SingleAnimation.cs
- PrintPageEvent.cs
- GacUtil.cs
- SplashScreenNativeMethods.cs
- TemplateControlParser.cs
- DragDrop.cs