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
- PublisherMembershipCondition.cs
- RegexCharClass.cs
- XmlValidatingReaderImpl.cs
- ZipIOEndOfCentralDirectoryBlock.cs
- NegotiateStream.cs
- XmlException.cs
- UnitySerializationHolder.cs
- EventLogEntryCollection.cs
- CompressEmulationStream.cs
- CommentEmitter.cs
- ExceptionValidationRule.cs
- ServiceHost.cs
- Logging.cs
- FormViewUpdateEventArgs.cs
- DataGridViewAutoSizeColumnModeEventArgs.cs
- DockPanel.cs
- ValidationHelper.cs
- Emitter.cs
- CssTextWriter.cs
- TdsParserStateObject.cs
- PolicyManager.cs
- Operators.cs
- TemplateNameScope.cs
- Tile.cs
- XmlDataSourceView.cs
- ListControl.cs
- TracedNativeMethods.cs
- VisualBasicImportReference.cs
- FrameDimension.cs
- LogFlushAsyncResult.cs
- CreatingCookieEventArgs.cs
- Trace.cs
- XmlSchemaSimpleType.cs
- URI.cs
- _ConnectOverlappedAsyncResult.cs
- RawStylusSystemGestureInputReport.cs
- ActivityWithResultConverter.cs
- CancelEventArgs.cs
- FontCollection.cs
- InternalBase.cs
- SmiEventSink_DeferedProcessing.cs
- Propagator.ExtentPlaceholderCreator.cs
- PopOutPanel.cs
- XamlReaderHelper.cs
- ProgressiveCrcCalculatingStream.cs
- DataRelationPropertyDescriptor.cs
- LinqDataSourceSelectEventArgs.cs
- Base64Decoder.cs
- CompilationRelaxations.cs
- ProgressBar.cs
- SoapCodeExporter.cs
- SqlExpressionNullability.cs
- ClockController.cs
- TrueReadOnlyCollection.cs
- ApplicationCommands.cs
- Pen.cs
- RadioButtonAutomationPeer.cs
- InstanceHandleReference.cs
- DispatcherObject.cs
- Command.cs
- SoapMessage.cs
- CompilerCollection.cs
- XmlAtomicValue.cs
- ConfigXmlWhitespace.cs
- RepeatInfo.cs
- RegisteredExpandoAttribute.cs
- SigningCredentials.cs
- CreateRefExpr.cs
- XmlObjectSerializerReadContext.cs
- NavigationCommands.cs
- FunctionNode.cs
- EntryWrittenEventArgs.cs
- ArraySet.cs
- DataMisalignedException.cs
- PropertyMappingExceptionEventArgs.cs
- DesignTimeTemplateParser.cs
- SqlCommand.cs
- DateTimeSerializationSection.cs
- RegionData.cs
- ReverseInheritProperty.cs
- JapaneseCalendar.cs
- mediaclock.cs
- SqlNodeTypeOperators.cs
- ResponseStream.cs
- TextEditorSelection.cs
- EntityRecordInfo.cs
- DocumentManager.cs
- ResizeGrip.cs
- SafeRightsManagementEnvironmentHandle.cs
- UrlPath.cs
- HttpVersion.cs
- KeyFrames.cs
- HttpMethodAttribute.cs
- SqlBinder.cs
- MailAddressCollection.cs
- EqualityArray.cs
- PerformanceCounters.cs
- Int32Converter.cs
- CacheHelper.cs
- SystemFonts.cs