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
- SQLMoneyStorage.cs
- RecognizerInfo.cs
- WindowVisualStateTracker.cs
- _SslState.cs
- PackageFilter.cs
- DocumentViewerHelper.cs
- XPathScanner.cs
- PropertyBuilder.cs
- BrowserTree.cs
- MissingFieldException.cs
- RequestCache.cs
- NativeMethodsCLR.cs
- _AutoWebProxyScriptEngine.cs
- DBBindings.cs
- DrawingContextWalker.cs
- SetterBase.cs
- DefaultEventAttribute.cs
- SchemaImporter.cs
- CustomCategoryAttribute.cs
- DetailsView.cs
- ActivityCodeGenerator.cs
- TextureBrush.cs
- ColorConverter.cs
- TreeWalkHelper.cs
- LinearGradientBrush.cs
- XslAstAnalyzer.cs
- OleStrCAMarshaler.cs
- Transform.cs
- IdnMapping.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- EdmToObjectNamespaceMap.cs
- _DynamicWinsockMethods.cs
- OracleSqlParser.cs
- RoleManagerModule.cs
- XmlCollation.cs
- OSEnvironmentHelper.cs
- Parsers.cs
- PrimitiveXmlSerializers.cs
- _LazyAsyncResult.cs
- UrlMappingsSection.cs
- WinInet.cs
- EmbeddedObject.cs
- PathFigureCollection.cs
- RequestCacheEntry.cs
- EpmContentSerializerBase.cs
- _NativeSSPI.cs
- Region.cs
- EntityCollection.cs
- SqlConnectionPoolProviderInfo.cs
- CodeAttributeDeclaration.cs
- ToolStripStatusLabel.cs
- CaseStatement.cs
- CompilerCollection.cs
- Baml2006ReaderContext.cs
- DescriptionAttribute.cs
- MultiTrigger.cs
- WinFormsSpinner.cs
- SqlBulkCopyColumnMappingCollection.cs
- XmlNamespaceManager.cs
- TextRange.cs
- SystemGatewayIPAddressInformation.cs
- QueryGenerator.cs
- CommandEventArgs.cs
- SrgsElementFactory.cs
- EditingMode.cs
- EmptyEnumerable.cs
- DataGridBoolColumn.cs
- ParameterBuilder.cs
- DataControlFieldHeaderCell.cs
- BasicCellRelation.cs
- DependencyObjectProvider.cs
- WebContext.cs
- DataServices.cs
- MetadataStore.cs
- DataGridBeginningEditEventArgs.cs
- FormsAuthenticationEventArgs.cs
- PolyBezierSegment.cs
- SelectionProcessor.cs
- __Filters.cs
- PropertyCondition.cs
- XmlSerializationWriter.cs
- MasterPage.cs
- CheckoutException.cs
- FontInfo.cs
- GenerateHelper.cs
- ProcessExitedException.cs
- HttpCookie.cs
- UTF8Encoding.cs
- WMIInterop.cs
- cryptoapiTransform.cs
- WebZone.cs
- Descriptor.cs
- TextTreePropertyUndoUnit.cs
- ReflectionPermission.cs
- DesignerPerfEventProvider.cs
- RegexBoyerMoore.cs
- DiagnosticTraceSource.cs
- CoordinationService.cs
- TextModifier.cs
- OutOfProcStateClientManager.cs