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
- TimeSpanConverter.cs
- ModifiableIteratorCollection.cs
- SafePEFileHandle.cs
- NavigationWindowAutomationPeer.cs
- XmlSchemaComplexType.cs
- OrthographicCamera.cs
- EdmValidator.cs
- GridViewRowCollection.cs
- ElementNotAvailableException.cs
- FontStyle.cs
- WebServiceTypeData.cs
- StickyNoteContentControl.cs
- TypeSystem.cs
- DisplayClaim.cs
- WebHeaderCollection.cs
- CharEnumerator.cs
- ExpressionParser.cs
- Brush.cs
- SecUtil.cs
- VSWCFServiceContractGenerator.cs
- CompatibleIComparer.cs
- TextChange.cs
- WindowsFormsDesignerOptionService.cs
- RIPEMD160.cs
- BooleanExpr.cs
- ProfilePropertyNameValidator.cs
- XmlDictionaryReader.cs
- InvariantComparer.cs
- TripleDES.cs
- ImpersonationContext.cs
- BinHexEncoder.cs
- FacetValueContainer.cs
- SourceSwitch.cs
- CharacterString.cs
- MessageBox.cs
- WebConfigurationFileMap.cs
- ProfilePropertySettingsCollection.cs
- DefaultAsyncDataDispatcher.cs
- Form.cs
- SynchronizationFilter.cs
- SqlGenericUtil.cs
- BitmapPalette.cs
- PathFigureCollectionValueSerializer.cs
- HighContrastHelper.cs
- SerialPort.cs
- TagPrefixCollection.cs
- BeginStoryboard.cs
- ADMembershipUser.cs
- MouseDevice.cs
- RuleRef.cs
- RoleManagerEventArgs.cs
- RelationshipType.cs
- GridViewDeletedEventArgs.cs
- ReferencedType.cs
- ChunkedMemoryStream.cs
- NamespaceEmitter.cs
- URLIdentityPermission.cs
- ICspAsymmetricAlgorithm.cs
- ColumnMapProcessor.cs
- CodeSnippetCompileUnit.cs
- QilFunction.cs
- MailHeaderInfo.cs
- LoaderAllocator.cs
- CAGDesigner.cs
- VirtualPathUtility.cs
- XmlBinaryWriter.cs
- SmtpNegotiateAuthenticationModule.cs
- NodeFunctions.cs
- Visitors.cs
- SoapAttributes.cs
- ProfessionalColorTable.cs
- AnimationStorage.cs
- Inline.cs
- PenLineJoinValidation.cs
- PartialList.cs
- PriorityQueue.cs
- MonikerProxyAttribute.cs
- FileStream.cs
- DbProviderFactory.cs
- SspiNegotiationTokenAuthenticatorState.cs
- SafeSecurityHandles.cs
- OletxCommittableTransaction.cs
- ListViewInsertedEventArgs.cs
- IndexedSelectQueryOperator.cs
- WebPartManagerInternals.cs
- DataGridViewTopRowAccessibleObject.cs
- LayeredChannelFactory.cs
- XsltOutput.cs
- DomainUpDown.cs
- QilBinary.cs
- UnicastIPAddressInformationCollection.cs
- ClosureBinding.cs
- BinHexEncoder.cs
- XmlException.cs
- DataStreams.cs
- XmlSignatureProperties.cs
- SoapMessage.cs
- Size.cs
- ApplicationId.cs
- Glyph.cs