Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / SafeRsaProviderHandle.cs / 1 / SafeRsaProviderHandle.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace Microsoft.InfoCards { using System; using System.ComponentModel; using System.Globalization; using System.Runtime.InteropServices; using System.Runtime.ConstrainedExecution; using System.Security; using Microsoft.InfoCards.Diagnostics; using IDT=Microsoft.InfoCards.Diagnostics.InfoCardTrace; // // Summary: // Provides a wrapper over a handle retrieved by CryptAcquireContext // internal class SafeRsaProviderHandle : SafeHandle { [DllImport( "advapi32.dll", EntryPoint ="CryptAcquireContextW", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true ) ] [SuppressUnmanagedCodeSecurity] private static extern bool CryptAcquireContext( [Out] out SafeRsaProviderHandle hProv, [In] string pszContainer, [In] string pszProvider, [In] uint dwProvType, [In] uint dwFlags ); [DllImport( "advapi32.dll", EntryPoint = "CryptReleaseContext", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true ) ] [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] [SuppressUnmanagedCodeSecurity] private static extern bool CryptReleaseContext( [In] IntPtr hProv, [In] uint dwFlags ); public static SafeRsaProviderHandle Construct() { // // The native provider we use to do encryption and decryption and associated constants to // set up the Microsoft Enhanced RSA and AES provider // const uint CRYPT_VERIFYCONTEXT = 0xF0000000; const byte PROV_RSA_AES = 24; // // We use a null provider and CRYPT_VERIFYCONTEXT as a flag // to force the use of ephemeral keys. See http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B238187 // for details. // SafeRsaProviderHandle h; if( !SafeRsaProviderHandle.CryptAcquireContext( out h, null, null, PROV_RSA_AES, CRYPT_VERIFYCONTEXT ) ) { Win32Exception e = new Win32Exception( Marshal.GetLastWin32Error() ); IDT.CloseInvalidOutSafeHandle(h); IDT.TraceAndLogException( e ); throw IDT.ThrowHelperError( new CommunicationException( e.Message ) ); } return h; } private SafeRsaProviderHandle() : base( IntPtr.Zero, true ) { } public override bool IsInvalid { get { return ( IntPtr.Zero == base.handle ); } } protected override bool ReleaseHandle() { #pragma warning suppress 56523 return CryptReleaseContext( base.handle, 0 ); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SpellerError.cs
- HtmlEncodedRawTextWriter.cs
- DataGridView.cs
- Pair.cs
- Security.cs
- DelegateTypeInfo.cs
- Positioning.cs
- AutomationElement.cs
- TCEAdapterGenerator.cs
- QuinticEase.cs
- CompilerCollection.cs
- RangeBase.cs
- Encoder.cs
- ThousandthOfEmRealDoubles.cs
- ContentControl.cs
- VerificationAttribute.cs
- AttributeCollection.cs
- OracleInternalConnection.cs
- LinearQuaternionKeyFrame.cs
- CodeMemberMethod.cs
- EnumMemberAttribute.cs
- PropertyChangedEventManager.cs
- ExtendedPropertyCollection.cs
- EventLevel.cs
- WebResourceUtil.cs
- TabControlCancelEvent.cs
- PageThemeBuildProvider.cs
- IsolationInterop.cs
- autovalidator.cs
- XPathAxisIterator.cs
- ProfileGroupSettings.cs
- XhtmlStyleClass.cs
- Baml6ConstructorInfo.cs
- ValueSerializerAttribute.cs
- AuthenticationConfig.cs
- ProjectionCamera.cs
- SystemInformation.cs
- SEHException.cs
- NetDataContractSerializer.cs
- _HelperAsyncResults.cs
- ImpersonateTokenRef.cs
- HelpFileFileNameEditor.cs
- InfoCardRSAPKCS1KeyExchangeFormatter.cs
- GeneralTransform3DGroup.cs
- EdmProviderManifest.cs
- BrushValueSerializer.cs
- WindowsSlider.cs
- Currency.cs
- AsymmetricCryptoHandle.cs
- PolicyManager.cs
- ProgressBarHighlightConverter.cs
- HandleRef.cs
- XmlWrappingReader.cs
- EdmItemCollection.OcAssemblyCache.cs
- ListBase.cs
- ProbeDuplex11AsyncResult.cs
- LambdaCompiler.Binary.cs
- ManipulationDeltaEventArgs.cs
- EpmCustomContentDeSerializer.cs
- BitmapEffectDrawingContextWalker.cs
- TcpChannelHelper.cs
- WebPartMenuStyle.cs
- DSACryptoServiceProvider.cs
- WindowsBrush.cs
- ValidationRuleCollection.cs
- listitem.cs
- QuotedStringWriteStateInfo.cs
- ScrollProperties.cs
- BuildProvidersCompiler.cs
- ListView.cs
- GatewayDefinition.cs
- SoapException.cs
- TableParaClient.cs
- ResourceReferenceKeyNotFoundException.cs
- XmlSchemaObject.cs
- ToolTip.cs
- AssemblySettingAttributes.cs
- SafeNativeMethodsMilCoreApi.cs
- CmsInterop.cs
- CollectionBuilder.cs
- TemplateKeyConverter.cs
- TreeNodeEventArgs.cs
- ReadOnlyDataSource.cs
- PartEditor.cs
- FilePrompt.cs
- C14NUtil.cs
- MetadataSource.cs
- AtomMaterializer.cs
- WebPermission.cs
- TimeSpan.cs
- CommentEmitter.cs
- VisualStyleRenderer.cs
- EDesignUtil.cs
- AvtEvent.cs
- GridViewItemAutomationPeer.cs
- WebControlsSection.cs
- VectorAnimationUsingKeyFrames.cs
- MimeXmlReflector.cs
- BulletedListEventArgs.cs
- DecimalAnimationBase.cs