Code:
/ 4.0 / 4.0 / 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. // ==++== // // 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
- MessageBodyMemberAttribute.cs
- XmlDeclaration.cs
- FileInfo.cs
- CodeComment.cs
- DataTableMappingCollection.cs
- FontFamilyIdentifier.cs
- SocketElement.cs
- MsiStyleLogWriter.cs
- COMException.cs
- StylusButton.cs
- CodeSnippetStatement.cs
- CommittableTransaction.cs
- SqlCacheDependencyDatabaseCollection.cs
- ProvidersHelper.cs
- DbProviderConfigurationHandler.cs
- RealizedColumnsBlock.cs
- TemplateBindingExtension.cs
- MsmqInputSessionChannel.cs
- CodeAssignStatement.cs
- KeyValueConfigurationElement.cs
- TextEffectCollection.cs
- XPathParser.cs
- ListBox.cs
- OleDbConnectionInternal.cs
- EventsTab.cs
- CustomLineCap.cs
- TabControlAutomationPeer.cs
- SimpleColumnProvider.cs
- KeySpline.cs
- WebControlsSection.cs
- DataObjectMethodAttribute.cs
- KeyValuePair.cs
- WorkflowHostingEndpoint.cs
- ProxyElement.cs
- MobileUserControl.cs
- TextFormatterImp.cs
- ObjectDataSourceMethodEventArgs.cs
- DataGridHelper.cs
- OrderByLifter.cs
- MergeFailedEvent.cs
- ISCIIEncoding.cs
- MobileRedirect.cs
- DataGridTablesFactory.cs
- AutomationTextAttribute.cs
- LinkedResource.cs
- WebSysDescriptionAttribute.cs
- ZipFileInfo.cs
- DropSource.cs
- CodeArrayCreateExpression.cs
- Axis.cs
- NativeCppClassAttribute.cs
- ItemCollection.cs
- SafeSecurityHandles.cs
- HtmlImage.cs
- Base64Encoder.cs
- SqlServer2KCompatibilityAnnotation.cs
- TokenBasedSetEnumerator.cs
- ToolBarDesigner.cs
- SqlBinder.cs
- LinqDataSourceInsertEventArgs.cs
- SoapSchemaMember.cs
- RawStylusInput.cs
- FilteredXmlReader.cs
- StrongNameIdentityPermission.cs
- DataView.cs
- PipeStream.cs
- RenderTargetBitmap.cs
- ExceptionHandler.cs
- TraceEventCache.cs
- HtmlElementErrorEventArgs.cs
- WpfPayload.cs
- XmlObjectSerializerReadContextComplex.cs
- AnnotationComponentChooser.cs
- HitTestResult.cs
- Cloud.cs
- TemplateBindingExpression.cs
- PeerResolverBindingElement.cs
- HostingEnvironmentSection.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- DrawItemEvent.cs
- UnknownBitmapDecoder.cs
- InkPresenter.cs
- LinkTarget.cs
- InstanceKeyNotReadyException.cs
- TypeUtil.cs
- MiniConstructorInfo.cs
- InternalControlCollection.cs
- WindowsClaimSet.cs
- HtmlInputHidden.cs
- SamlAuthenticationStatement.cs
- Codec.cs
- CodeTypeReferenceCollection.cs
- DragDeltaEventArgs.cs
- DbParameterCollectionHelper.cs
- DecodeHelper.cs
- BindingCompleteEventArgs.cs
- SharedUtils.cs
- ViewCellRelation.cs
- DesignTimeData.cs
- Queue.cs