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
- ConfigXmlText.cs
- DelegatedStream.cs
- SafeRegistryHandle.cs
- OpenTypeLayoutCache.cs
- EmissiveMaterial.cs
- PocoPropertyAccessorStrategy.cs
- EFAssociationProvider.cs
- SessionEndedEventArgs.cs
- HttpClientCertificate.cs
- StylusLogic.cs
- SmtpReplyReader.cs
- Hashtable.cs
- GlyphRunDrawing.cs
- ProgressBarRenderer.cs
- DataGridViewColumn.cs
- HtmlTableRowCollection.cs
- DefaultAuthorizationContext.cs
- StructuredType.cs
- CommandConverter.cs
- SamlSubjectStatement.cs
- ArraySortHelper.cs
- ActivityPropertyReference.cs
- ServiceDiscoveryBehavior.cs
- SamlConditions.cs
- RelatedImageListAttribute.cs
- AspNetHostingPermission.cs
- FloatAverageAggregationOperator.cs
- Expressions.cs
- TrackingParameters.cs
- Activator.cs
- RenderData.cs
- MasterPage.cs
- WebPartMinimizeVerb.cs
- ToolTip.cs
- PerformanceCounters.cs
- OracleMonthSpan.cs
- WhitespaceRuleLookup.cs
- ScriptIgnoreAttribute.cs
- EntryIndex.cs
- CellLabel.cs
- RawMouseInputReport.cs
- AttributeTableBuilder.cs
- ConfigUtil.cs
- KeyedCollection.cs
- PropertyGroupDescription.cs
- AdRotator.cs
- Item.cs
- LambdaCompiler.Address.cs
- LineSegment.cs
- OutputCacheSection.cs
- SelectedCellsCollection.cs
- PropertyKey.cs
- MemberMemberBinding.cs
- MLangCodePageEncoding.cs
- CollectionEditor.cs
- ValidationHelpers.cs
- SiteMapDataSourceView.cs
- GridProviderWrapper.cs
- Icon.cs
- InputMethodStateTypeInfo.cs
- UnrecognizedAssertionsBindingElement.cs
- XmlParserContext.cs
- IPCCacheManager.cs
- Internal.cs
- Pair.cs
- SplitterPanel.cs
- RectConverter.cs
- HtmlEmptyTagControlBuilder.cs
- Configuration.cs
- ParentQuery.cs
- RawMouseInputReport.cs
- TextFormatterHost.cs
- WebPartConnection.cs
- LayoutInformation.cs
- BasicExpandProvider.cs
- DecimalKeyFrameCollection.cs
- OneOfConst.cs
- DataGridDetailsPresenter.cs
- PrivilegeNotHeldException.cs
- DelegateHelpers.cs
- XmlSchemaSimpleTypeList.cs
- TextParagraphView.cs
- KerberosRequestorSecurityToken.cs
- sqlpipe.cs
- DataGridColumnFloatingHeader.cs
- TypeSystem.cs
- StrongNameUtility.cs
- LinkedResourceCollection.cs
- PointAnimationUsingKeyFrames.cs
- DecimalFormatter.cs
- StringArrayConverter.cs
- ColumnMapTranslator.cs
- XmlReturnWriter.cs
- CreateUserWizard.cs
- WindowsAuthenticationModule.cs
- EdmFunctionAttribute.cs
- PolicyManager.cs
- BufferModeSettings.cs
- StrongNamePublicKeyBlob.cs
- ModelItemKeyValuePair.cs