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
- DataPager.cs
- SqlGatherConsumedAliases.cs
- SettingsPropertyNotFoundException.cs
- CodeMemberMethod.cs
- TreeNodeMouseHoverEvent.cs
- XmlMemberMapping.cs
- ConnectionInterfaceCollection.cs
- XmlDataSourceNodeDescriptor.cs
- InputBinding.cs
- InstanceCompleteException.cs
- documentsequencetextpointer.cs
- Events.cs
- RequestQueue.cs
- AnimationLayer.cs
- GenericAuthenticationEventArgs.cs
- DropShadowBitmapEffect.cs
- IriParsingElement.cs
- EllipseGeometry.cs
- QueryPageSettingsEventArgs.cs
- EmptyStringExpandableObjectConverter.cs
- AtomServiceDocumentSerializer.cs
- Point.cs
- SignatureToken.cs
- GridViewSelectEventArgs.cs
- DataGridCellItemAutomationPeer.cs
- TemplateControlBuildProvider.cs
- ResXDataNode.cs
- ExpressionParser.cs
- SafeNativeMethodsOther.cs
- Rijndael.cs
- AnnouncementInnerClient11.cs
- HttpStreamFormatter.cs
- DBCommand.cs
- BindingListCollectionView.cs
- NotifyCollectionChangedEventArgs.cs
- NumericPagerField.cs
- TypeToken.cs
- NextPreviousPagerField.cs
- PassportPrincipal.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- FormsAuthenticationTicket.cs
- EndEvent.cs
- _AutoWebProxyScriptHelper.cs
- CompositeDataBoundControl.cs
- RecordManager.cs
- XmlComment.cs
- WizardPanel.cs
- MissingManifestResourceException.cs
- HttpApplication.cs
- NamespaceQuery.cs
- XmlQualifiedNameTest.cs
- NativeMethods.cs
- DataComponentGenerator.cs
- PackageDigitalSignatureManager.cs
- APCustomTypeDescriptor.cs
- DecoderBestFitFallback.cs
- ListViewInsertedEventArgs.cs
- ListItemConverter.cs
- RecommendedAsConfigurableAttribute.cs
- DTCTransactionManager.cs
- BatchServiceHost.cs
- _HeaderInfoTable.cs
- FilterUserControlBase.cs
- DataBoundControlAdapter.cs
- WebPart.cs
- StylusPointPropertyInfo.cs
- Point.cs
- AliasExpr.cs
- ComplexTypeEmitter.cs
- NativeMethods.cs
- _SslState.cs
- XPathDescendantIterator.cs
- ProcessingInstructionAction.cs
- DataBoundControl.cs
- DataObject.cs
- ConfigurationSettings.cs
- SafeSystemMetrics.cs
- LockCookie.cs
- SqlFileStream.cs
- DataServiceClientException.cs
- ExtenderProviderService.cs
- WindowsSolidBrush.cs
- SapiRecoInterop.cs
- NotFiniteNumberException.cs
- TextEditorMouse.cs
- DataServiceQuery.cs
- AuthenticationModuleElementCollection.cs
- ItemCheckEvent.cs
- DiscoveryDocumentLinksPattern.cs
- BaseTemplateCodeDomTreeGenerator.cs
- WpfMemberInvoker.cs
- XmlNodeReader.cs
- PassportPrincipal.cs
- IOException.cs
- Viewport3DAutomationPeer.cs
- ImageDrawing.cs
- Int16.cs
- ColumnMapCopier.cs
- KeyboardEventArgs.cs
- CustomAttribute.cs