本文整理汇总了C#中System.Security.Cryptography.Xml.KeyInfo.GetXml方法的典型用法代码示例。如果您正苦于以下问题:C# KeyInfo.GetXml方法的具体用法?C# KeyInfo.GetXml怎么用?C# KeyInfo.GetXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.Xml.KeyInfo
的用法示例。
在下文中一共展示了KeyInfo.GetXml方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateKeyDescriptors
/// <summary>
/// Creates the necessary key descriptors for the metadata based on the certificate in the IDPConfig class.
/// </summary>
/// <returns></returns>
private static KeyDescriptor[] CreateKeyDescriptors()
{
List<KeyDescriptor> keys = new List<KeyDescriptor>();
// Pack the certificate.
KeyInfo keyinfo = new KeyInfo();
KeyInfoX509Data keyClause = new KeyInfoX509Data(IDPConfig.IDPCertificate, X509IncludeOption.EndCertOnly);
keyinfo.AddClause(keyClause);
{ // Create signing key element.
KeyDescriptor key = new KeyDescriptor();
keys.Add(key);
key.use = KeyTypes.signing;
key.useSpecified = true;
key.KeyInfo = Serialization.DeserializeFromXmlString<dk.nita.saml20.Schema.XmlDSig.KeyInfo>(keyinfo.GetXml().OuterXml);
}
{ // Create encryption key element
KeyDescriptor key = new KeyDescriptor();
keys.Add(key);
key.use = KeyTypes.encryption;
key.useSpecified = true;
key.KeyInfo = Serialization.DeserializeFromXmlString<dk.nita.saml20.Schema.XmlDSig.KeyInfo>(keyinfo.GetXml().OuterXml);
}
return keys.ToArray();
}
示例2: SignedXmlHelper
static SignedXmlHelper()
{
var keyInfo = new KeyInfo();
keyInfo.AddClause(new KeyInfoX509Data(TestCert));
KeyInfoXml = keyInfo.GetXml().OuterXml;
}
示例3: KeyDescriptor
private XObject KeyDescriptor(X509Certificate2 certificate, string keyType)
{
KeyInfo keyinfo = new KeyInfo();
keyinfo.AddClause(new KeyInfoX509Data(certificate, CertificateIncludeOption));
return new XElement(Saml2MetadataConstants.MetadataNamespaceX + Saml2MetadataConstants.Message.KeyDescriptor,
new XAttribute(Saml2MetadataConstants.Message.Use, keyType),
XElement.Parse(keyinfo.GetXml().OuterXml));
}
示例4: WriteContentsTo
public void WriteContentsTo (
AddressingVersion addressingVersion,
XmlDictionaryWriter writer)
{
if (writer == null)
throw new ArgumentNullException ("writer");
#if NET_2_1
writer.WriteString (Uri.AbsoluteUri);
#else
if (addressingVersion == AddressingVersion.None)
writer.WriteString (Uri.AbsoluteUri);
else {
writer.WriteStartElement ("Address", addressingVersion.Namespace);
writer.WriteString (Uri.AbsoluteUri);
writer.WriteEndElement ();
if (Headers != null)
foreach (AddressHeader ah in Headers)
ah.WriteAddressHeader (writer);
if (Identity == null)
return;
writer.WriteStartElement ("Identity", Constants.WsaIdentityUri);
X509CertificateEndpointIdentity x509 =
Identity as X509CertificateEndpointIdentity;
if (x509 != null) {
KeyInfo ki = new KeyInfo ();
KeyInfoX509Data x = new KeyInfoX509Data ();
foreach (X509Certificate2 cert in x509.Certificates)
x.AddCertificate (cert);
ki.AddClause (x);
ki.GetXml ().WriteTo (writer);
} else {
DataContractSerializer ds = new DataContractSerializer (Identity.IdentityClaim.GetType ());
ds.WriteObject (writer, Identity.IdentityClaim);
}
writer.WriteEndElement ();
}
#endif
}
示例5: ArgumentNullException
void IXmlSerializable.WriteXml (XmlWriter writer)
{
if (writer == null)
throw new ArgumentNullException ("writer");
writer.WriteStartElement ("Address", Constants.WsaNamespace);
writer.WriteString (address.Uri.AbsoluteUri);
writer.WriteEndElement ();
if (address.Identity == null)
return;
if (address.Headers != null)
foreach (AddressHeader ah in address.Headers)
ah.WriteAddressHeader (writer);
writer.WriteStartElement ("Identity", Constants.WsaIdentityUri);
#if !NET_2_1
X509CertificateEndpointIdentity x509 =
address.Identity as X509CertificateEndpointIdentity;
if (x509 != null) {
KeyInfo ki = new KeyInfo ();
KeyInfoX509Data x = new KeyInfoX509Data ();
foreach (X509Certificate2 cert in x509.Certificates)
x.AddCertificate (cert);
ki.AddClause (x);
ki.GetXml ().WriteTo (writer);
} else {
DataContractSerializer ds = new DataContractSerializer (address.Identity.IdentityClaim.GetType ());
ds.WriteObject (writer, address.Identity.IdentityClaim);
}
#endif
writer.WriteEndElement ();
}
示例6: ConvertToMetadata
//.........这里部分代码省略.........
{
Location = new Uri(baseUrl, endpoint.LocalPath).ToString()
};
logoutEndpoint.ResponseLocation = logoutEndpoint.Location;
logoutEndpoint.Binding = GetBinding(endpoint.Binding, Saml20Constants.ProtocolBindings.HttpRedirect);
logoutServiceEndpoints.Add(logoutEndpoint);
var artifactLogoutEndpoint = new IndexedEndpoint
{
Binding = Saml20Constants.ProtocolBindings.HttpSoap,
Index = endpoint.Index,
Location = logoutEndpoint.Location
};
artifactResolutionEndpoints.Add(artifactLogoutEndpoint);
continue;
}
}
serviceProviderDescriptor.SingleLogoutService = logoutServiceEndpoints.ToArray();
serviceProviderDescriptor.AssertionConsumerService = signonServiceEndpoints.ToArray();
// Attribute consuming service.
if (config.Metadata.RequestedAttributes.Count > 0)
{
var attConsumingService = new AttributeConsumingService();
serviceProviderDescriptor.AttributeConsumingService = new[] { attConsumingService };
attConsumingService.Index = signonServiceEndpoints[0].Index;
attConsumingService.IsDefault = true;
attConsumingService.ServiceName = new[] { new LocalizedName("SP", "en") };
attConsumingService.RequestedAttribute = new RequestedAttribute[config.Metadata.RequestedAttributes.Count];
for (var i = 0; i < config.Metadata.RequestedAttributes.Count; i++)
{
attConsumingService.RequestedAttribute[i] = new RequestedAttribute
{
Name = config.Metadata.RequestedAttributes[i].Name
};
if (config.Metadata.RequestedAttributes[i].IsRequired)
{
attConsumingService.RequestedAttribute[i].IsRequired = true;
}
attConsumingService.RequestedAttribute[i].NameFormat = SamlAttribute.NameformatBasic;
}
}
else
{
serviceProviderDescriptor.AttributeConsumingService = new AttributeConsumingService[0];
}
if (config.Metadata == null || !config.Metadata.ExcludeArtifactEndpoints)
{
serviceProviderDescriptor.ArtifactResolutionService = artifactResolutionEndpoints.ToArray();
}
entity.Items = new object[] { serviceProviderDescriptor };
// Keyinfo
var keySigning = new KeyDescriptor();
var keyEncryption = new KeyDescriptor();
serviceProviderDescriptor.KeyDescriptor = new[] { keySigning, keyEncryption };
keySigning.Use = KeyTypes.Signing;
keySigning.UseSpecified = true;
keyEncryption.Use = KeyTypes.Encryption;
keyEncryption.UseSpecified = true;
// Ugly conversion between the .Net framework classes and our classes ... avert your eyes!!
keySigning.KeyInfo = Serialization.DeserializeFromXmlString<Schema.XmlDSig.KeyInfo>(keyInfo.GetXml().OuterXml);
keyEncryption.KeyInfo = keySigning.KeyInfo;
// apply the <Organization> element
if (config.Metadata.Organization.ElementInformation.IsPresent)
{
entity.Organization = new Organization
{
OrganizationName = new[] { new LocalizedName { Value = config.Metadata.Organization.Name } },
OrganizationDisplayName = new[] { new LocalizedName { Value = config.Metadata.Organization.DisplayName } },
OrganizationURL = new[] { new LocalizedURI { Value = config.Metadata.Organization.Url } }
};
}
if (config.Metadata.Contacts != null && config.Metadata.Contacts.Count > 0)
{
entity.ContactPerson = config.Metadata.Contacts.Select(x => new Contact
{
ContactType =
(Schema.Metadata.ContactType)
((int)x.Type),
Company = x.Company,
GivenName = x.GivenName,
SurName = x.SurName,
EmailAddress = new[] { x.Email },
TelephoneNumber = new[] { x.Phone }
}).ToArray();
}
}
示例7: ConvertToMetadata
//.........这里部分代码省略.........
loginEndpoint.isDefault = true;
loginEndpoint.Location = new Uri(baseURL, endpoint.localPath).ToString();
loginEndpoint.Binding = GetBinding(endpoint.Binding, Saml20Constants.ProtocolBindings.HTTP_Post);
signonServiceEndpoints.Add(loginEndpoint);
IndexedEndpoint artifactSignonEndpoint = new IndexedEndpoint();
artifactSignonEndpoint.Binding = Saml20Constants.ProtocolBindings.HTTP_SOAP;
artifactSignonEndpoint.index = loginEndpoint.index;
artifactSignonEndpoint.Location = loginEndpoint.Location;
artifactResolutionEndpoints.Add(artifactSignonEndpoint);
continue;
}
if (endpoint.endpointType == EndpointType.LOGOUT)
{
Endpoint logoutEndpoint = new Endpoint();
logoutEndpoint.Location = new Uri(baseURL, endpoint.localPath).ToString();
logoutEndpoint.ResponseLocation = logoutEndpoint.Location;
logoutEndpoint.Binding = GetBinding(endpoint.Binding, Saml20Constants.ProtocolBindings.HTTP_Post);
logoutServiceEndpoints.Add(logoutEndpoint);
logoutEndpoint = new Endpoint();
logoutEndpoint.Location = new Uri(baseURL, endpoint.localPath).ToString();
logoutEndpoint.ResponseLocation = logoutEndpoint.Location;
logoutEndpoint.Binding = GetBinding(endpoint.Binding, Saml20Constants.ProtocolBindings.HTTP_Redirect);
logoutServiceEndpoints.Add(logoutEndpoint);
IndexedEndpoint artifactLogoutEndpoint = new IndexedEndpoint();
artifactLogoutEndpoint.Binding = Saml20Constants.ProtocolBindings.HTTP_SOAP;
artifactLogoutEndpoint.index = endpoint.endPointIndex;
artifactLogoutEndpoint.Location = logoutEndpoint.Location;
artifactResolutionEndpoints.Add(artifactLogoutEndpoint);
continue;
}
}
spDescriptor.SingleLogoutService = logoutServiceEndpoints.ToArray();
spDescriptor.AssertionConsumerService = signonServiceEndpoints.ToArray();
// NameIdFormat
if (!string.IsNullOrEmpty(config.NameIdFormat))
{
spDescriptor.NameIDFormat = new string[] { config.NameIdFormat };
}
// Attribute consuming service.
if (config.RequestedAttributes.Attributes.Count > 0)
{
AttributeConsumingService attConsumingService = new AttributeConsumingService();
spDescriptor.AttributeConsumingService = new AttributeConsumingService[] { attConsumingService };
attConsumingService.index = signonServiceEndpoints[0].index;
attConsumingService.isDefault = true;
attConsumingService.ServiceName = new LocalizedName[] { new LocalizedName("SP", "da") };
attConsumingService.RequestedAttribute =
new RequestedAttribute[config.RequestedAttributes.Attributes.Count];
for (int i = 0; i < config.RequestedAttributes.Attributes.Count; i++)
{
attConsumingService.RequestedAttribute[i] = new RequestedAttribute();
attConsumingService.RequestedAttribute[i].Name = config.RequestedAttributes.Attributes[i].name;
if (config.RequestedAttributes.Attributes[i].IsRequired)
attConsumingService.RequestedAttribute[i].isRequired = true;
attConsumingService.RequestedAttribute[i].NameFormat = SamlAttribute.NAMEFORMAT_BASIC;
}
}
else
{
spDescriptor.AttributeConsumingService = new AttributeConsumingService[0];
}
if(config.Metadata != null && config.Metadata.IncludeArtifactEndpoints)
spDescriptor.ArtifactResolutionService = artifactResolutionEndpoints.ToArray();
entity.Items = new object[] { spDescriptor };
// Keyinfo
KeyDescriptor keySigning = new KeyDescriptor();
KeyDescriptor keyEncryption = new KeyDescriptor();
spDescriptor.KeyDescriptor = new KeyDescriptor[] { keySigning, keyEncryption };
keySigning.use = KeyTypes.signing;
keySigning.useSpecified = true;
keyEncryption.use = KeyTypes.encryption;
keyEncryption.useSpecified = true;
// Ugly conversion between the .Net framework classes and our classes ... avert your eyes!!
keySigning.KeyInfo = Serialization.DeserializeFromXmlString<Schema.XmlDSig.KeyInfo>(keyinfo.GetXml().OuterXml);
keyEncryption.KeyInfo = keySigning.KeyInfo;
// apply the <Organization> element
if (config.ServiceProvider.Organization != null)
entity.Organization = config.ServiceProvider.Organization;
if (config.ServiceProvider.ContactPerson != null && config.ServiceProvider.ContactPerson.Count > 0)
entity.ContactPerson = config.ServiceProvider.ContactPerson.ToArray();
}