Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / RsaKeyIdentifierClause.cs / 1305376 / RsaKeyIdentifierClause.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Tokens { using System.Globalization; using System.Security.Cryptography; using System.Xml; public class RsaKeyIdentifierClause : SecurityKeyIdentifierClause { static string clauseType = XmlSignatureStrings.Namespace + XmlSignatureStrings.RsaKeyValue; readonly RSA rsa; readonly RSAParameters rsaParameters; RsaSecurityKey rsaSecurityKey; public RsaKeyIdentifierClause(RSA rsa) : base(clauseType) { if (rsa == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rsa"); this.rsa = rsa; this.rsaParameters = rsa.ExportParameters(false); } public override bool CanCreateKey { get { return true; } } public RSA Rsa { get { return this.rsa; } } public override SecurityKey CreateKey() { if (this.rsaSecurityKey == null) { this.rsaSecurityKey = new RsaSecurityKey(this.rsa); } return this.rsaSecurityKey; } public byte[] GetExponent() { return SecurityUtils.CloneBuffer(this.rsaParameters.Exponent); } public byte[] GetModulus() { return SecurityUtils.CloneBuffer(this.rsaParameters.Modulus); } public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause) { RsaKeyIdentifierClause that = keyIdentifierClause as RsaKeyIdentifierClause; // PreSharp Bug: Parameter 'that' to this public method must be validated: A null-dereference can occur here. #pragma warning suppress 56506 return ReferenceEquals(this, that) || (that != null && that.Matches(this.rsa)); } public bool Matches(RSA rsa) { if (rsa == null) return false; RSAParameters rsaParameters = rsa.ExportParameters(false); return SecurityUtils.MatchesBuffer(this.rsaParameters.Modulus, rsaParameters.Modulus) && SecurityUtils.MatchesBuffer(this.rsaParameters.Exponent, rsaParameters.Exponent); } public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "RsaKeyIdentifierClause(Modulus = {0}, Exponent = {1})", Convert.ToBase64String(this.rsaParameters.Modulus), Convert.ToBase64String(this.rsaParameters.Exponent)); } public void WriteExponentAsBase64(XmlWriter writer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } writer.WriteBase64(this.rsaParameters.Exponent, 0, this.rsaParameters.Exponent.Length); } public void WriteModulusAsBase64(XmlWriter writer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } writer.WriteBase64(this.rsaParameters.Modulus, 0, this.rsaParameters.Modulus.Length); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.IdentityModel.Tokens { using System.Globalization; using System.Security.Cryptography; using System.Xml; public class RsaKeyIdentifierClause : SecurityKeyIdentifierClause { static string clauseType = XmlSignatureStrings.Namespace + XmlSignatureStrings.RsaKeyValue; readonly RSA rsa; readonly RSAParameters rsaParameters; RsaSecurityKey rsaSecurityKey; public RsaKeyIdentifierClause(RSA rsa) : base(clauseType) { if (rsa == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("rsa"); this.rsa = rsa; this.rsaParameters = rsa.ExportParameters(false); } public override bool CanCreateKey { get { return true; } } public RSA Rsa { get { return this.rsa; } } public override SecurityKey CreateKey() { if (this.rsaSecurityKey == null) { this.rsaSecurityKey = new RsaSecurityKey(this.rsa); } return this.rsaSecurityKey; } public byte[] GetExponent() { return SecurityUtils.CloneBuffer(this.rsaParameters.Exponent); } public byte[] GetModulus() { return SecurityUtils.CloneBuffer(this.rsaParameters.Modulus); } public override bool Matches(SecurityKeyIdentifierClause keyIdentifierClause) { RsaKeyIdentifierClause that = keyIdentifierClause as RsaKeyIdentifierClause; // PreSharp Bug: Parameter 'that' to this public method must be validated: A null-dereference can occur here. #pragma warning suppress 56506 return ReferenceEquals(this, that) || (that != null && that.Matches(this.rsa)); } public bool Matches(RSA rsa) { if (rsa == null) return false; RSAParameters rsaParameters = rsa.ExportParameters(false); return SecurityUtils.MatchesBuffer(this.rsaParameters.Modulus, rsaParameters.Modulus) && SecurityUtils.MatchesBuffer(this.rsaParameters.Exponent, rsaParameters.Exponent); } public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "RsaKeyIdentifierClause(Modulus = {0}, Exponent = {1})", Convert.ToBase64String(this.rsaParameters.Modulus), Convert.ToBase64String(this.rsaParameters.Exponent)); } public void WriteExponentAsBase64(XmlWriter writer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } writer.WriteBase64(this.rsaParameters.Exponent, 0, this.rsaParameters.Exponent.Length); } public void WriteModulusAsBase64(XmlWriter writer) { if (writer == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("writer"); } writer.WriteBase64(this.rsaParameters.Modulus, 0, this.rsaParameters.Modulus.Length); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- InputReferenceExpression.cs
- TableCellCollection.cs
- RegionIterator.cs
- DrawingImage.cs
- FormViewRow.cs
- WorkingDirectoryEditor.cs
- ErrorFormatterPage.cs
- DataSourceXmlSerializer.cs
- SettingsPropertyCollection.cs
- TextCompositionEventArgs.cs
- PropertyGrid.cs
- TraceSection.cs
- EmptyEnumerator.cs
- CustomDictionarySources.cs
- StructuralType.cs
- ContentType.cs
- AttributeEmitter.cs
- Point.cs
- TextProperties.cs
- FormsAuthenticationConfiguration.cs
- BrowserCapabilitiesFactory.cs
- LoginView.cs
- SafeBitVector32.cs
- FixedSOMLineRanges.cs
- SendMailErrorEventArgs.cs
- IDataContractSurrogate.cs
- FileDialogCustomPlace.cs
- TargetException.cs
- EUCJPEncoding.cs
- Ops.cs
- HandlerMappingMemo.cs
- MergeExecutor.cs
- ParamArrayAttribute.cs
- _ContextAwareResult.cs
- RemoteWebConfigurationHostStream.cs
- MemoryResponseElement.cs
- VirtualDirectoryMapping.cs
- BypassElement.cs
- Encoder.cs
- SafePipeHandle.cs
- HtmlElementCollection.cs
- DirectionalLight.cs
- ManipulationCompletedEventArgs.cs
- ImpersonateTokenRef.cs
- CellConstant.cs
- MbpInfo.cs
- RichTextBoxDesigner.cs
- ProtocolsConfiguration.cs
- JsonEnumDataContract.cs
- WeakEventTable.cs
- QilNode.cs
- WebDisplayNameAttribute.cs
- _HeaderInfo.cs
- AutoGeneratedFieldProperties.cs
- RuleConditionDialog.cs
- NamedPermissionSet.cs
- Faults.cs
- HttpRuntimeSection.cs
- DmlSqlGenerator.cs
- EventMappingSettingsCollection.cs
- OutOfMemoryException.cs
- PeerTransportListenAddressValidatorAttribute.cs
- LookupNode.cs
- WebPartHeaderCloseVerb.cs
- ContainerParaClient.cs
- ProfileParameter.cs
- ScriptMethodAttribute.cs
- ColumnHeader.cs
- StateRuntime.cs
- Trace.cs
- TimeIntervalCollection.cs
- XamlToRtfWriter.cs
- DefaultTraceListener.cs
- SqlStream.cs
- Annotation.cs
- Localizer.cs
- LexicalChunk.cs
- BitmapCache.cs
- ScrollViewerAutomationPeer.cs
- WebRequest.cs
- Rights.cs
- ProcessingInstructionAction.cs
- MdImport.cs
- Lock.cs
- DeadCharTextComposition.cs
- ZipIOModeEnforcingStream.cs
- DynamicDocumentPaginator.cs
- Decoder.cs
- PtsPage.cs
- WindowsAltTab.cs
- ConnectionPoolManager.cs
- PictureBox.cs
- HttpApplicationStateWrapper.cs
- HtmlMeta.cs
- InternalCache.cs
- RelationHandler.cs
- ConfigurationCollectionAttribute.cs
- OracleBinary.cs
- QilSortKey.cs
- RequestStatusBarUpdateEventArgs.cs