Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / infocard / Service / managed / Microsoft / InfoCards / SelfIssuedAuthAsymmetricKey.cs / 1 / SelfIssuedAuthAsymmetricKey.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- // namespace Microsoft.InfoCards { using System; using System.IdentityModel.Selectors; using System.IdentityModel.Tokens; using System.ServiceModel; using System.ServiceModel.Security; using System.ServiceModel.Security.Tokens; using System.Runtime.InteropServices; using System.Security.Cryptography; using System.IdentityModel; using System.Security.Cryptography.Xml; using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace; using System.Collections.ObjectModel; using System.Collections.Generic; // // For common & resources // using Microsoft.InfoCards; // // Summary: // This class implements a public/private AsymmetricSecurityKey // that safely handed to Indigo code // internal class SelfIssuedAuthAsymmetricKey : AsymmetricSecurityKey, IDisposable { SelfIssuedAuthRSACryptoProvider m_selfIssuedAuthRsaCryptoProvider; // // Summary: // Constructs a new SelfIssuedAuthAsymmetricCrypto given an SelfIssuedAuthRSACryptoProvider. // // Parameters: // cryptoHandle - the handle to the asymmetric key to base this crypto object on. public SelfIssuedAuthAsymmetricKey( RSACryptoServiceProvider rsa ) { m_selfIssuedAuthRsaCryptoProvider = new SelfIssuedAuthRSACryptoProvider( rsa ); } // // Summary: // Returns the size of the asymmetric key // public override int KeySize { get { return m_selfIssuedAuthRsaCryptoProvider.KeySize; } } // // Summary: // Indicates whether this IAsymmetricCrypto has access to the private key. // In our case, that's the whole point, so it always returns true. // public override bool HasPrivateKey() { IDT.ThrowInvalidArgumentConditional( m_selfIssuedAuthRsaCryptoProvider.IsPublicOnly(), "selfIssuedRsaCrypoProvider" ); return true; } // // Summary: // Returns a reference to the SelfIssuedAuthRSACryptoProvider that give Indigo access to // the private key associated with the infocard, recipient tuple. // // Parameters: // algorithmUri - The URI of the algorithm being requested. // privateKey - set to true if access to the private key is required. // public override AsymmetricAlgorithm GetAsymmetricAlgorithm( string algorithmUri, bool privateKey ) { switch ( algorithmUri ) { case SignedXml.XmlDsigRSASHA1Url: case EncryptedXml.XmlEncRSA15Url: case EncryptedXml.XmlEncRSAOAEPUrl: return m_selfIssuedAuthRsaCryptoProvider; default: throw IDT.ThrowHelperError( new NotSupportedException( SR.GetString( SR.ClientUnsupportedCryptoAlgorithm, algorithmUri ) ) ); } } // // Sumamry: // Returns a HashAlgorithm // // Parameters: // algorithmUri - the uri of the hash algorithm being requested. // public override HashAlgorithm GetHashAlgorithmForSignature( string algorithmUri ) { switch ( algorithmUri ) { case SignedXml.XmlDsigRSASHA1Url: return new SHA1Managed(); default: throw IDT.ThrowHelperError( new NotSupportedException( SR.GetString( SR.UnsupportedSignatureAlgorithm, algorithmUri ) ) ); } } // // Summary: // Returns a Signature deformatter. // // Parameters: // algorithmUri - the uri of signature deformatter being requeted. // public override AsymmetricSignatureDeformatter GetSignatureDeformatter( string algorithmUri ) { switch ( algorithmUri ) { case SignedXml.XmlDsigRSASHA1Url: return new SelfIssuedAuthRSAPKCS1SignatureDeformatter( m_selfIssuedAuthRsaCryptoProvider ); default: throw IDT.ThrowHelperError( new NotSupportedException( SR.GetString( SR.UnsupportedSignatureAlgorithm, algorithmUri ) ) ); } } // // Summary: // Returns a Signature formatter. // // Parameters: // algorithmUri - the uri of signature formatter being requeted. // public override AsymmetricSignatureFormatter GetSignatureFormatter( string algorithmUri ) { switch ( algorithmUri ) { case SignedXml.XmlDsigRSASHA1Url: return new SelfIssuedAuthRSAPKCS1SignatureFormatter( m_selfIssuedAuthRsaCryptoProvider ); default: throw IDT.ThrowHelperError( new NotSupportedException( SR.GetString( SR.UnsupportedSignatureAlgorithm, algorithmUri ) ) ); } } // // Summary: // Decrypts a symmetric key using the private key of a public/private key pair. // // Parameters: // algorithmUri - The algorithm to use to decrypt the key. // keyData - the key to decrypt. // public override byte[ ] DecryptKey( string algorithmUri, byte[ ] keyData ) { // // Encrypt/Decrypt should not be happenning in a proof token // throw IDT.ThrowHelperError( new NotSupportedException() ); } // // Summary: // Encrypts a symmetric key using the public key of a public/private key pair. // // Parameters: // algorithmUri - The algorithm to use to encrypt the key. // keyData - the key to encrypt. // public override byte[ ] EncryptKey( string algorithmUri, byte[ ] keyData ) { // // Encrypt/Decrypt should not be happenning in a proof token // throw IDT.ThrowHelperError( new NotSupportedException() ); } public override bool IsSupportedAlgorithm( string algorithmUri ) { switch (algorithmUri) { case SignedXml.XmlDsigRSASHA1Url: case EncryptedXml.XmlEncRSA15Url: case EncryptedXml.XmlEncRSAOAEPUrl: return true; default: return false; } } public override bool IsSymmetricAlgorithm( string algorithmUri ) { return InfoCardCryptoHelper.IsSymmetricAlgorithm(algorithmUri); } public override bool IsAsymmetricAlgorithm( string algorithmUri ) { return InfoCardCryptoHelper.IsAsymmetricAlgorithm(algorithmUri); } public void Dispose() { if ( null != m_selfIssuedAuthRsaCryptoProvider ) { ( ( IDisposable )m_selfIssuedAuthRsaCryptoProvider ).Dispose(); m_selfIssuedAuthRsaCryptoProvider = null; } } } } // 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
- PipelineModuleStepContainer.cs
- SafeRightsManagementQueryHandle.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- WebControl.cs
- EditorPart.cs
- SecurityDocument.cs
- WebPartTransformer.cs
- DataGridViewDataConnection.cs
- ObfuscationAttribute.cs
- CategoryAttribute.cs
- LoginName.cs
- BinaryMethodMessage.cs
- TemplateComponentConnector.cs
- ToolStripPanelDesigner.cs
- FontUnitConverter.cs
- RichTextBoxDesigner.cs
- UnitySerializationHolder.cs
- ValidatorUtils.cs
- Cursor.cs
- TopClause.cs
- RedirectionProxy.cs
- GridItemCollection.cs
- AppLevelCompilationSectionCache.cs
- AlignmentYValidation.cs
- SafeArrayRankMismatchException.cs
- TemporaryBitmapFile.cs
- BinaryNode.cs
- ToolboxItemAttribute.cs
- _AutoWebProxyScriptEngine.cs
- SafeNativeMethodsMilCoreApi.cs
- GridEntryCollection.cs
- DataGridView.cs
- XmlAutoDetectWriter.cs
- XamlParser.cs
- StackBuilderSink.cs
- TableDetailsRow.cs
- OTFRasterizer.cs
- VarRefManager.cs
- PageContentAsyncResult.cs
- TrackingServices.cs
- UInt32Storage.cs
- WebPartManagerDesigner.cs
- SystemColorTracker.cs
- URLIdentityPermission.cs
- EqualityComparer.cs
- VScrollBar.cs
- XmlComment.cs
- EntityAdapter.cs
- SqlCacheDependencyDatabase.cs
- TableStyle.cs
- PrintPreviewDialog.cs
- UserInitiatedNavigationPermission.cs
- WebPartConnectionsCloseVerb.cs
- CodeObjectCreateExpression.cs
- WebPartsPersonalization.cs
- AjaxFrameworkAssemblyAttribute.cs
- KerberosRequestorSecurityToken.cs
- SystemWebCachingSectionGroup.cs
- ToolStripLocationCancelEventArgs.cs
- NonVisualControlAttribute.cs
- IPAddressCollection.cs
- MemoryRecordBuffer.cs
- GetUserPreferenceRequest.cs
- HttpCacheVaryByContentEncodings.cs
- ObjectCloneHelper.cs
- EditCommandColumn.cs
- VisualStyleRenderer.cs
- VirtualPath.cs
- XmlEntityReference.cs
- QueryPageSettingsEventArgs.cs
- LinqDataSource.cs
- ContentHostHelper.cs
- ButtonDesigner.cs
- SymmetricAlgorithm.cs
- ListViewItem.cs
- BitmapEffectState.cs
- JpegBitmapEncoder.cs
- DesignerSerializerAttribute.cs
- GlobalizationSection.cs
- ConnectionProviderAttribute.cs
- XmlNotation.cs
- TextRangeSerialization.cs
- DataProtection.cs
- MultiDataTrigger.cs
- ManagedFilter.cs
- WebPartAuthorizationEventArgs.cs
- Registry.cs
- ActivityBindForm.Designer.cs
- TitleStyle.cs
- DataGridRow.cs
- LightweightCodeGenerator.cs
- PathSegmentCollection.cs
- InvalidPrinterException.cs
- QuotedPrintableStream.cs
- WebBrowserNavigatingEventHandler.cs
- Configuration.cs
- ExceptionCollection.cs
- PartialCachingControl.cs
- CopyEncoder.cs
- ListControl.cs