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
- ToolStripManager.cs
- BitmapEffectState.cs
- HierarchicalDataBoundControlAdapter.cs
- SplitterCancelEvent.cs
- WindowsGraphicsWrapper.cs
- BindingNavigator.cs
- CallContext.cs
- Graphics.cs
- LoadRetryHandler.cs
- ExpressionEditorSheet.cs
- VisualStyleElement.cs
- DataQuery.cs
- NullToBooleanConverter.cs
- SourceFileInfo.cs
- ProfileEventArgs.cs
- GetPageNumberCompletedEventArgs.cs
- DSASignatureFormatter.cs
- Msmq4SubqueuePoisonHandler.cs
- JoinGraph.cs
- TextLineResult.cs
- CollectionExtensions.cs
- XmlSignificantWhitespace.cs
- ButtonFieldBase.cs
- SystemGatewayIPAddressInformation.cs
- UrlMappingsSection.cs
- NumberFormatInfo.cs
- ResourceContainer.cs
- ServiceDescriptionData.cs
- ClientConfigurationSystem.cs
- SystemKeyConverter.cs
- MarkupExtensionSerializer.cs
- ComboBoxAutomationPeer.cs
- ControlPersister.cs
- XmlParser.cs
- BamlLocalizabilityResolver.cs
- NGCSerializer.cs
- Number.cs
- UpdateExpressionVisitor.cs
- DbParameterCollection.cs
- TripleDESCryptoServiceProvider.cs
- ObservableCollection.cs
- Pkcs7Recipient.cs
- ItemChangedEventArgs.cs
- SerializerWriterEventHandlers.cs
- ZipIOExtraFieldZip64Element.cs
- CrossContextChannel.cs
- ListItemParagraph.cs
- ValueQuery.cs
- FileInfo.cs
- KeyConstraint.cs
- WpfKnownType.cs
- ColumnPropertiesGroup.cs
- TextBlock.cs
- TextTreeRootNode.cs
- WorkItem.cs
- ProxyGenerator.cs
- StyleCollection.cs
- Statements.cs
- SQLCharsStorage.cs
- ContainerCodeDomSerializer.cs
- SmiMetaDataProperty.cs
- ToolStripPanelRow.cs
- XPathParser.cs
- EpmCustomContentSerializer.cs
- Paragraph.cs
- Variant.cs
- MissingManifestResourceException.cs
- ValueSerializer.cs
- ServiceModelConfigurationSection.cs
- Int16Converter.cs
- CustomErrorsSectionWrapper.cs
- IPGlobalProperties.cs
- PopOutPanel.cs
- basecomparevalidator.cs
- EndpointAddressMessageFilterTable.cs
- ConnectionPool.cs
- Exceptions.cs
- Oci.cs
- Timer.cs
- HotCommands.cs
- WorkflowOperationErrorHandler.cs
- ArgIterator.cs
- TraversalRequest.cs
- UseLicense.cs
- XmlRootAttribute.cs
- RuleSetReference.cs
- PowerEase.cs
- DataTemplate.cs
- RegexCharClass.cs
- BackEase.cs
- ImportOptions.cs
- Mouse.cs
- LogArchiveSnapshot.cs
- HtmlTernaryTree.cs
- TemplatedAdorner.cs
- UriParserTemplates.cs
- XmlImplementation.cs
- EmptyQuery.cs
- PermissionAttributes.cs
- GB18030Encoding.cs