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
- Configuration.cs
- DocumentsTrace.cs
- ObjectHandle.cs
- DBCommandBuilder.cs
- AssemblyAttributesGoHere.cs
- TriState.cs
- SwitchElementsCollection.cs
- StaticContext.cs
- XmlDataSourceNodeDescriptor.cs
- DataColumnPropertyDescriptor.cs
- XmlComment.cs
- Stacktrace.cs
- ApplicationTrust.cs
- DataGridViewRowPrePaintEventArgs.cs
- Image.cs
- WindowsTab.cs
- ConfigurationSectionCollection.cs
- DataContractSerializerSection.cs
- IgnoreSection.cs
- DependencyPropertyAttribute.cs
- PropertyInfo.cs
- ValidationEventArgs.cs
- LogManagementAsyncResult.cs
- MtomMessageEncoder.cs
- GeneralTransformCollection.cs
- ProgressBarRenderer.cs
- WebResourceAttribute.cs
- XmlQuerySequence.cs
- ColumnMapCopier.cs
- KeyNotFoundException.cs
- EditorZoneBase.cs
- ImageList.cs
- AsyncStreamReader.cs
- TraceSection.cs
- assertwrapper.cs
- JapaneseCalendar.cs
- FileAuthorizationModule.cs
- DoubleLink.cs
- InsufficientMemoryException.cs
- XmlLanguageConverter.cs
- CodeIdentifiers.cs
- SectionVisual.cs
- LocalIdCollection.cs
- MemberExpression.cs
- StylusPointDescription.cs
- SoapElementAttribute.cs
- BuildProvider.cs
- DataListCommandEventArgs.cs
- DispatcherOperation.cs
- Vector3D.cs
- ConditionalAttribute.cs
- PersonalizationProviderHelper.cs
- ConnectionOrientedTransportManager.cs
- StylusPointPropertyInfo.cs
- ResourceAssociationSetEnd.cs
- FlowNode.cs
- ProxyGenerator.cs
- FrameworkContentElement.cs
- Vector3DCollectionConverter.cs
- DesignerActionGlyph.cs
- SchemaTableOptionalColumn.cs
- OleDbPropertySetGuid.cs
- ChildTable.cs
- GroupQuery.cs
- SwitchElementsCollection.cs
- DisplayClaim.cs
- ManifestSignatureInformation.cs
- ApplicationInfo.cs
- ServiceAuthorizationElement.cs
- XmlILModule.cs
- ToolStripPanelCell.cs
- InternalConfigEventArgs.cs
- QueryStringHandler.cs
- Canvas.cs
- XmlSchemaSimpleTypeRestriction.cs
- ResourceReader.cs
- NamedPipeWorkerProcess.cs
- TCPClient.cs
- LinearGradientBrush.cs
- hresults.cs
- ClientTargetSection.cs
- TabControlDesigner.cs
- ConnectionManagementSection.cs
- objectquery_tresulttype.cs
- MatrixStack.cs
- FormsAuthenticationTicket.cs
- TdsParserSessionPool.cs
- PreviewPrintController.cs
- Transaction.cs
- InternalCache.cs
- BinaryFormatterSinks.cs
- CompareValidator.cs
- ListViewUpdatedEventArgs.cs
- SQLInt32.cs
- Collection.cs
- ResourceDescriptionAttribute.cs
- SelectionWordBreaker.cs
- PeerCustomResolverSettings.cs
- ProgressBarRenderer.cs
- MultipleViewProviderWrapper.cs