Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / RsaEndpointIdentity.cs / 1 / RsaEndpointIdentity.cs
//---------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel { using System; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.ServiceModel.Security; using System.Xml; using System.Xml.Serialization; public class RsaEndpointIdentity : EndpointIdentity { public RsaEndpointIdentity(string publicKey) { if (publicKey == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("publicKey"); base.Initialize(Claim.CreateRsaClaim(ToRsa(publicKey))); } public RsaEndpointIdentity(X509Certificate2 certificate) { if (certificate == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("certificate"); #pragma warning suppress 56506 // A Certificate Public key can never be null. RSA rsa = certificate.PublicKey.Key as RSA; if (rsa == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.GetString(SR.PublicKeyNotRSA))); base.Initialize(Claim.CreateRsaClaim(rsa)); } public RsaEndpointIdentity(Claim identity) { if (identity == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("identity"); // PreSharp Bug: Parameter 'identity.ClaimType' to this public method must be validated: A null-dereference can occur here. #pragma warning suppress 56506 // Claim.ClaimType will never return null if (!identity.ClaimType.Equals(ClaimTypes.Rsa)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.UnrecognizedClaimTypeForIdentity, identity.ClaimType, ClaimTypes.Rsa)); base.Initialize(identity); } internal RsaEndpointIdentity(XmlDictionaryReader reader) { reader.ReadStartElement(XD.XmlSignatureDictionary.RsaKeyValue, XD.XmlSignatureDictionary.Namespace); byte[] modulus = Convert.FromBase64String(reader.ReadElementString(XD.XmlSignatureDictionary.Modulus.Value, XD.XmlSignatureDictionary.Namespace.Value)); byte[] exponent = Convert.FromBase64String(reader.ReadElementString(XD.XmlSignatureDictionary.Exponent.Value, XD.XmlSignatureDictionary.Namespace.Value)); reader.ReadEndElement(); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); RSAParameters parameters = new RSAParameters(); parameters.Exponent = exponent; parameters.Modulus = modulus; rsa.ImportParameters(parameters); base.Initialize(Claim.CreateRsaClaim(rsa)); } internal override void WriteContentsTo(XmlDictionaryWriter writer) { if (writer == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.KeyInfo, XD.XmlSignatureDictionary.Namespace); writer.WriteStartElement(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.RsaKeyValue, XD.XmlSignatureDictionary.Namespace); RSA rsa = (RSA) this.IdentityClaim.Resource; RSAParameters parameters = rsa.ExportParameters(false); writer.WriteElementString(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.Modulus, XD.XmlSignatureDictionary.Namespace, Convert.ToBase64String(parameters.Modulus)); writer.WriteElementString(XD.XmlSignatureDictionary.Prefix.Value, XD.XmlSignatureDictionary.Exponent, XD.XmlSignatureDictionary.Namespace, Convert.ToBase64String(parameters.Exponent)); writer.WriteEndElement(); writer.WriteEndElement(); } static RSA ToRsa(string keyString) { if (keyString == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("keyString"); RSA rsa = new RSACryptoServiceProvider(); rsa.FromXmlString(keyString); return rsa; } } } // 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
- BaseTreeIterator.cs
- SR.cs
- ProxyGenerator.cs
- IdnMapping.cs
- UIElementHelper.cs
- Point3DCollectionConverter.cs
- XPathSingletonIterator.cs
- PolygonHotSpot.cs
- BuildResult.cs
- PropertyDescriptorCollection.cs
- IndexedGlyphRun.cs
- UInt32.cs
- RenderingEventArgs.cs
- DataGridTablesFactory.cs
- MaskedTextBox.cs
- QuaternionAnimationUsingKeyFrames.cs
- CodeAccessSecurityEngine.cs
- CompletedAsyncResult.cs
- WeakReadOnlyCollection.cs
- FixedSOMTextRun.cs
- RemoteWebConfigurationHostServer.cs
- ToolBar.cs
- EntityDataSourceDesignerHelper.cs
- ObjectToIdCache.cs
- ParsedAttributeCollection.cs
- GridItem.cs
- MasterPageCodeDomTreeGenerator.cs
- GlobalizationAssembly.cs
- SeekStoryboard.cs
- LayoutEngine.cs
- XmlSchemaObject.cs
- MobileDeviceCapabilitiesSectionHandler.cs
- RuntimeResourceSet.cs
- SectionInput.cs
- CallbackException.cs
- QueryValue.cs
- Overlapped.cs
- StructuralType.cs
- TextCompositionManager.cs
- DesignerOptionService.cs
- ModelTreeEnumerator.cs
- CheckedPointers.cs
- SqlTrackingService.cs
- GridItemPatternIdentifiers.cs
- PropertyOrder.cs
- CodeConditionStatement.cs
- CharAnimationBase.cs
- LocalizableAttribute.cs
- SQLChars.cs
- SqlDependencyUtils.cs
- EventlogProvider.cs
- ECDiffieHellman.cs
- BitArray.cs
- AsymmetricSignatureFormatter.cs
- InvokeProviderWrapper.cs
- ApplicationManager.cs
- XmlSchemaDocumentation.cs
- TextRangeEditTables.cs
- String.cs
- DurationConverter.cs
- XamlTreeBuilderBamlRecordWriter.cs
- ArgIterator.cs
- DynamicValidatorEventArgs.cs
- DataErrorValidationRule.cs
- _NtlmClient.cs
- ToolStripPanelRenderEventArgs.cs
- TreeWalkHelper.cs
- AssociationTypeEmitter.cs
- AggregateNode.cs
- SqlClientFactory.cs
- DataRelationCollection.cs
- Int64KeyFrameCollection.cs
- SymbolMethod.cs
- EntityParameterCollection.cs
- XmlNodeWriter.cs
- ToolStripGripRenderEventArgs.cs
- SystemParameters.cs
- Vector3DIndependentAnimationStorage.cs
- _OverlappedAsyncResult.cs
- CodeGenerator.cs
- ButtonBaseAdapter.cs
- Point3DCollectionConverter.cs
- GridViewColumn.cs
- mda.cs
- SkinIDTypeConverter.cs
- PathGeometry.cs
- ListChunk.cs
- PrintDialog.cs
- VerbConverter.cs
- GeometryDrawing.cs
- UpdatePanelControlTrigger.cs
- DefaultMemberAttribute.cs
- PseudoWebRequest.cs
- TableLayoutPanel.cs
- ModelItemKeyValuePair.cs
- ToolStripRendererSwitcher.cs
- AbstractSvcMapFileLoader.cs
- QueryRewriter.cs
- PerformanceCounterLib.cs
- ResourcePropertyMemberCodeDomSerializer.cs