Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Core / Microsoft / Win32 / SafeHandles / BCryptSafeHandles.cs / 1305376 / BCryptSafeHandles.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== using System; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; using System.Security; using System.Security.Cryptography; using System.Diagnostics.Contracts; namespace Microsoft.Win32.SafeHandles { ////// SafeHandle representing a BCRYPT_ALG_HANDLE /// //// #pragma warning disable 618 // Have not migrated to v4 transparency yet [System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)] #pragma warning restore 618 internal sealed class SafeBCryptAlgorithmHandle : SafeHandleZeroOrMinusOneIsInvalid { private SafeBCryptAlgorithmHandle() : base(true) { } [DllImport("bcrypt")] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SuppressUnmanagedCodeSecurity] private static extern BCryptNative.ErrorCode BCryptCloseAlgorithmProvider(IntPtr hAlgorithm, int flags); protected override bool ReleaseHandle() { return BCryptCloseAlgorithmProvider(handle, 0) == BCryptNative.ErrorCode.Success; } } ///// /// Safe handle representing a BCRYPT_HASH_HANDLE and the associated buffer holding the hash object /// //// #pragma warning disable 618 // Have not migrated to v4 transparency yet [System.Security.SecurityCritical(System.Security.SecurityCriticalScope.Everything)] #pragma warning restore 618 internal sealed class SafeBCryptHashHandle : SafeHandleZeroOrMinusOneIsInvalid { private IntPtr m_hashObject; private SafeBCryptHashHandle() : base(true) { } ///// /// Buffer holding the hash object. This buffer should be allocated with Marshal.AllocCoTaskMem. /// internal IntPtr HashObject { get { return m_hashObject; } set { Contract.Requires(value != IntPtr.Zero); m_hashObject = value; } } [DllImport("bcrypt")] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SuppressUnmanagedCodeSecurity] private static extern BCryptNative.ErrorCode BCryptDestroyHash(IntPtr hHash); protected override bool ReleaseHandle() { bool success = BCryptDestroyHash(handle) == BCryptNative.ErrorCode.Success; // The hash object buffer must be released only after destroying the hash handle if (m_hashObject != IntPtr.Zero) { Marshal.FreeCoTaskMem(m_hashObject); } return success; } } } // 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
- OdbcHandle.cs
- AnnotationDocumentPaginator.cs
- BitmapEffectInputData.cs
- DataGridViewAdvancedBorderStyle.cs
- XamlVector3DCollectionSerializer.cs
- PagePropertiesChangingEventArgs.cs
- _ConnectOverlappedAsyncResult.cs
- XmlSchemaInfo.cs
- DependencyPropertyValueSerializer.cs
- BinHexEncoder.cs
- DmlSqlGenerator.cs
- AggregatePushdown.cs
- TemplateKey.cs
- RuntimeConfig.cs
- ListViewTableRow.cs
- BitmapImage.cs
- QueryCacheEntry.cs
- XmlImplementation.cs
- TouchFrameEventArgs.cs
- ParameterCollection.cs
- PropertyTabChangedEvent.cs
- InvalidChannelBindingException.cs
- configsystem.cs
- PageThemeParser.cs
- DebugHandleTracker.cs
- EntryPointNotFoundException.cs
- MergeFailedEvent.cs
- SqlUtil.cs
- ExtensionFile.cs
- DefaultValueAttribute.cs
- HitTestParameters.cs
- CompositeScriptReferenceEventArgs.cs
- UnauthorizedWebPart.cs
- XPathBinder.cs
- SqlDataSourceConnectionPanel.cs
- ComboBox.cs
- EndpointBehaviorElementCollection.cs
- HttpHandlerAction.cs
- HandleRef.cs
- PropertyDescriptorGridEntry.cs
- HtmlGenericControl.cs
- XmlNamespaceMapping.cs
- CodeTypeReferenceExpression.cs
- SHA384Cng.cs
- CharacterShapingProperties.cs
- XmlDataSourceNodeDescriptor.cs
- Delay.cs
- CodeCompiler.cs
- CodePrimitiveExpression.cs
- MessageTransmitTraceRecord.cs
- LiteralSubsegment.cs
- CreateUserWizardStep.cs
- ApplicationSettingsBase.cs
- ColorContextHelper.cs
- RelationalExpressions.cs
- CommandID.cs
- ToReply.cs
- LayoutEditorPart.cs
- BitVec.cs
- PageAsyncTaskManager.cs
- PerformanceCounter.cs
- LicenseProviderAttribute.cs
- RSAPKCS1SignatureFormatter.cs
- DataGridViewRowsAddedEventArgs.cs
- ColumnTypeConverter.cs
- ObjectView.cs
- FilterQueryOptionExpression.cs
- ResXResourceSet.cs
- XmlC14NWriter.cs
- Type.cs
- WebPart.cs
- HtmlShim.cs
- loginstatus.cs
- NetDataContractSerializer.cs
- StorageInfo.cs
- Buffer.cs
- SHA1Managed.cs
- ValidationSummary.cs
- EventSetter.cs
- TimestampInformation.cs
- HotCommands.cs
- ClientTargetCollection.cs
- SqlNodeAnnotation.cs
- UserControl.cs
- HierarchicalDataBoundControl.cs
- ProgressBarBrushConverter.cs
- TypefaceMetricsCache.cs
- LeftCellWrapper.cs
- CroppedBitmap.cs
- ParallelTimeline.cs
- AxisAngleRotation3D.cs
- PinnedBufferMemoryStream.cs
- ExecutionScope.cs
- PageSettings.cs
- SharedMemory.cs
- PropertySet.cs
- HwndHost.cs
- PageEventArgs.cs
- ToolStripDropDownClosingEventArgs.cs
- ElementAtQueryOperator.cs