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
- TraceSource.cs
- DefaultShape.cs
- CodeGenerator.cs
- WebRequestModulesSection.cs
- TextModifierScope.cs
- DataGridViewSelectedColumnCollection.cs
- ConfigurationHelpers.cs
- TdsRecordBufferSetter.cs
- NetTcpSectionData.cs
- EntityDataSource.cs
- CodeGeneratorOptions.cs
- Cast.cs
- ListBox.cs
- AddingNewEventArgs.cs
- NativeWindow.cs
- Point3DAnimationUsingKeyFrames.cs
- IResourceProvider.cs
- ProcessHostFactoryHelper.cs
- ActiveXContainer.cs
- EUCJPEncoding.cs
- RawStylusInputReport.cs
- RepeaterDesigner.cs
- ToolStripRenderEventArgs.cs
- XmlQuerySequence.cs
- EventLogTraceListener.cs
- VisemeEventArgs.cs
- FileNotFoundException.cs
- MetafileHeader.cs
- KeyConstraint.cs
- keycontainerpermission.cs
- ValidationError.cs
- BamlRecords.cs
- XsltInput.cs
- AcceptorSessionSymmetricTransportSecurityProtocol.cs
- XmlSchemaAnnotation.cs
- UInt64Storage.cs
- WinInet.cs
- AtomServiceDocumentSerializer.cs
- XmlCollation.cs
- Query.cs
- TextParagraphCache.cs
- UITypeEditor.cs
- Evaluator.cs
- ProfileServiceManager.cs
- ReferentialConstraint.cs
- URLIdentityPermission.cs
- MonitorWrapper.cs
- OleDbParameterCollection.cs
- FontUnit.cs
- PasswordTextContainer.cs
- PermissionAttributes.cs
- Delay.cs
- SingleAnimation.cs
- Random.cs
- CanExecuteRoutedEventArgs.cs
- DataControlField.cs
- EventProviderWriter.cs
- DesignerHierarchicalDataSourceView.cs
- BamlLocalizer.cs
- Pen.cs
- ToolTip.cs
- WebConfigurationFileMap.cs
- ActivityStateQuery.cs
- CommandPlan.cs
- BigInt.cs
- UmAlQuraCalendar.cs
- AnimationStorage.cs
- streamingZipPartStream.cs
- Console.cs
- BehaviorDragDropEventArgs.cs
- ThreadExceptionDialog.cs
- AnimationClockResource.cs
- RSACryptoServiceProvider.cs
- DropSource.cs
- TreeViewTemplateSelector.cs
- DesignerLoader.cs
- SafeRegistryHandle.cs
- RealizationDrawingContextWalker.cs
- SchemaDeclBase.cs
- ApplicationId.cs
- PipeStream.cs
- EntityDesignerUtils.cs
- TreeNodeBindingDepthConverter.cs
- Module.cs
- SlotInfo.cs
- ExpressionCopier.cs
- DbReferenceCollection.cs
- JavaScriptString.cs
- LogicalExpr.cs
- PrincipalPermission.cs
- GlobalizationSection.cs
- AttributedMetaModel.cs
- X509ScopedServiceCertificateElement.cs
- ParallelDesigner.cs
- EdmSchemaError.cs
- InfoCardServiceInstallComponent.cs
- ScrollItemPatternIdentifiers.cs
- Point.cs
- HitTestParameters.cs
- Adorner.cs