Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / RemoteX509AsymmetricSecurityKey.cs / 1 / RemoteX509AsymmetricSecurityKey.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.InfoCards
{
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
using System.IdentityModel.Tokens;
using System.ServiceModel;
using System.ServiceModel.Security;
using System.ServiceModel.Security.Tokens;
using IDT=Microsoft.InfoCards.Diagnostics.InfoCardTrace;
//
// Summary:
// Remotes all PrivateKey operations to the RPC service running in the agent.
// Any public key operations are performed with the local public key
//
class RemoteX509AsymmetricSecurityKey : X509AsymmetricSecurityKey, IDisposable
{
X509Certificate2 m_cert;
object m_sync;
bool m_disposed;
public RemoteX509AsymmetricSecurityKey(X509Certificate2 cert)
: base( cert )
{
m_cert = cert;
//
// If the key is not our special remote key, we shouldn't be using
// this object.
//
if( !( m_cert.PrivateKey is RemoteCryptoRsaServiceProvider) )
{
throw IDT.ThrowHelperError( new NotSupportedException() );
}
m_sync = new object();
}
//
// Summary:
// Return a specified key set.
//
// Arguments:
// algorithmUri: the name of the algorithm
// privateKey: indicates if the private key (remote key) is returned.
//
public override AsymmetricAlgorithm GetAsymmetricAlgorithm(string algorithmUri, bool privateKey)
{
if( !IsSupportedAlgorithm( algorithmUri ) )
{
throw IDT.ThrowHelperError( new NotSupportedException() );
}
return base.GetAsymmetricAlgorithm( algorithmUri, privateKey );
}
//
// Summary:
// Returns the Signature verifier
//
public override AsymmetricSignatureDeformatter GetSignatureDeformatter(string algorithmUri)
{
if( !IsSupportedAlgorithm( algorithmUri ) )
{
throw IDT.ThrowHelperError( new NotSupportedException() );
}
//
// This will use the public key, which we don't need to wrap.
//
return base.GetSignatureDeformatter( algorithmUri );
}
//
// Summary:
// Returns the Signature creator
//
public override AsymmetricSignatureFormatter GetSignatureFormatter(string algorithmUri)
{
if( !IsSupportedAlgorithm( algorithmUri ) )
{
throw IDT.ThrowHelperError( new NotSupportedException() );
}
//
// The private key object must be our special private key.
//
RemoteAsymmetricSignatureFormatter formatter = new RemoteAsymmetricSignatureFormatter();
formatter.SetKey( m_cert.PrivateKey );
return formatter;
}
//
// Summary:
// Tests if a specific algorithm is supported.
//
public override bool IsSupportedAlgorithm(string algorithmUri)
{
switch (algorithmUri)
{
case SignedXml.XmlDsigRSASHA1Url:
case EncryptedXml.XmlEncRSA15Url:
case EncryptedXml.XmlEncRSAOAEPUrl:
return base.IsSupportedAlgorithm( algorithmUri );
case SignedXml.XmlDsigDSAUrl:
default:
return false;
}
}
void IDisposable.Dispose()
{
if ( m_disposed )
{
return;
}
lock( m_sync )
{
if( m_disposed )
{
return;
}
m_disposed = true;
IDisposable disposable = m_cert.PrivateKey as IDisposable;
if( null != disposable )
{
disposable.Dispose();
}
disposable = m_cert.PublicKey.Key as IDisposable;
if( null != disposable )
{
disposable.Dispose();
}
}
}
}
}
// 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
- BasicCellRelation.cs
- TargetParameterCountException.cs
- EnterpriseServicesHelper.cs
- EmbeddedMailObjectCollectionEditor.cs
- _LazyAsyncResult.cs
- MemberDescriptor.cs
- CellQuery.cs
- UserPreferenceChangedEventArgs.cs
- _Win32.cs
- SessionStateSection.cs
- Msmq4PoisonHandler.cs
- DodSequenceMerge.cs
- BridgeDataReader.cs
- _NegotiateClient.cs
- SpellerInterop.cs
- BindableTemplateBuilder.cs
- ScriptControl.cs
- TransportChannelListener.cs
- CodeEntryPointMethod.cs
- UnknownWrapper.cs
- ExpressionBinding.cs
- RequestQueue.cs
- OracleLob.cs
- BridgeDataReader.cs
- LingerOption.cs
- SynthesizerStateChangedEventArgs.cs
- WindowPattern.cs
- MenuEventArgs.cs
- AffineTransform3D.cs
- PlatformNotSupportedException.cs
- BaseTemplatedMobileComponentEditor.cs
- AuthenticationService.cs
- SoapParser.cs
- SplitterCancelEvent.cs
- DataGridViewButtonCell.cs
- SafeFileMappingHandle.cs
- TextOutput.cs
- HitTestResult.cs
- ServiceThrottle.cs
- StringArrayConverter.cs
- ArraySet.cs
- ReaderOutput.cs
- RIPEMD160.cs
- TextClipboardData.cs
- PatternMatcher.cs
- AnyAllSearchOperator.cs
- _DisconnectOverlappedAsyncResult.cs
- webclient.cs
- Enum.cs
- GroupedContextMenuStrip.cs
- ClientType.cs
- lengthconverter.cs
- WindowsStatusBar.cs
- TextModifierScope.cs
- PasswordBoxAutomationPeer.cs
- AdapterDictionary.cs
- XmlDocumentSerializer.cs
- XmlEnumAttribute.cs
- SafeEventLogWriteHandle.cs
- NetworkInformationException.cs
- BigInt.cs
- BridgeDataReader.cs
- FieldInfo.cs
- CodeTypeDelegate.cs
- Facet.cs
- SerTrace.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- DataGridViewSortCompareEventArgs.cs
- State.cs
- Stream.cs
- SplitterCancelEvent.cs
- storepermission.cs
- MasterPageParser.cs
- RemoteWebConfigurationHost.cs
- Point3DConverter.cs
- DataFormat.cs
- FacetValues.cs
- SafeHGlobalHandleCritical.cs
- UxThemeWrapper.cs
- ObjectQueryProvider.cs
- CompilationPass2Task.cs
- TextElementEnumerator.cs
- TypeBuilder.cs
- ImportCatalogPart.cs
- WebConfigManager.cs
- CodeExporter.cs
- AsymmetricSignatureFormatter.cs
- StateMachine.cs
- ComponentTray.cs
- GroupBox.cs
- DataGridViewLayoutData.cs
- HttpHeaderCollection.cs
- CompositionTarget.cs
- RuntimeArgumentHandle.cs
- XmlReturnReader.cs
- MetafileHeaderWmf.cs
- TTSVoice.cs
- TraceContext.cs
- WindowHelperService.cs
- Propagator.JoinPropagator.cs