XmlLicenseTransform 类

定义

表示用于对签名的 XrML 许可证进行标准化的许可证转换算法。

public ref class XmlLicenseTransform : System::Security::Cryptography::Xml::Transform
public class XmlLicenseTransform : System.Security.Cryptography.Xml.Transform
type XmlLicenseTransform = class
    inherit Transform
Public Class XmlLicenseTransform
Inherits Transform
继承
XmlLicenseTransform

示例

下面的代码示例演示如何使用 IRelDecryptor 接口和 XmlLicenseTransform 类验证 XML 数字签名。

void CheckSignatureWithEncryptedGrant(
    String^ fileName, IRelDecryptor^ decryptor)
{
    // Create a new XML document.
    XmlDocument^ sourceDocument = gcnew XmlDocument();
    XmlNamespaceManager^ namespaceManager =
        gcnew XmlNamespaceManager(sourceDocument->NameTable);

    // Format using white spaces.
    sourceDocument->PreserveWhitespace = true;

    // Load the passed XML file into the document.
    sourceDocument->Load(fileName);
    namespaceManager->AddNamespace("dsig",
        SignedXml::XmlDsigNamespaceUrl);

    // Find the "Signature" node and create a new
    // XmlNodeList object.
    XmlNodeList^ nodeList = 
        sourceDocument->SelectNodes("//dsig:Signature", namespaceManager);

    for (int i = 0, count = nodeList->Count; i < count; i++)
    {
        XmlDocument^ clone = (XmlDocument^) sourceDocument->Clone();
        XmlNodeList^ signatures =
            clone->SelectNodes("//dsig:Signature", namespaceManager);

        // Create a new SignedXml object and pass into it the
        // XML document clone.
        SignedXml^ signedDocument = gcnew SignedXml(clone);

        // Load the signature node.
        signedDocument->LoadXml((XmlElement^)signatures[i]);

        // Set the context for license transform
        Transform^ licenseTransform = ((Reference^)signedDocument->
            SignedInfo->References[0])->TransformChain[0];

        if ((licenseTransform::typeid == XmlLicenseTransform::typeid) 
            && (decryptor != nullptr))
        {
            // Decryptor is used to decrypt encryptedGrant
            // elements.
            ((XmlLicenseTransform^) licenseTransform)->Decryptor = decryptor;
        }

        // Check the signature and display the result.
        if (signedDocument->CheckSignature())
        {
            Console::WriteLine("SUCCESS: " +
                "CheckSignatureWithEncryptedGrant - issuer index #" + i);
        }
        else
        {
            Console::WriteLine("FAILURE: " +
                "CheckSignatureWithEncryptedGrant - issuer index #" + i);
        }
    }
}
public static void CheckSignatureWithEncryptedGrant(string fileName, IRelDecryptor decryptor)
{
    // Create a new XML document.
    XmlDocument xmlDocument = new XmlDocument();
    XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlDocument.NameTable);

    // Format using white spaces.
    xmlDocument.PreserveWhitespace = true;

    // Load the passed XML file into the document.
    xmlDocument.Load(fileName);
    nsManager.AddNamespace("dsig", SignedXml.XmlDsigNamespaceUrl);

    // Find the "Signature" node and create a new XmlNodeList object.
    XmlNodeList nodeList = xmlDocument.SelectNodes("//dsig:Signature", nsManager);

    for (int i = 0, count = nodeList.Count; i < count; i++)
    {
        XmlDocument clone = xmlDocument.Clone() as XmlDocument;
        XmlNodeList signatures = clone.SelectNodes("//dsig:Signature", nsManager);

        // Create a new SignedXml object and pass into it the XML document clone.
        SignedXml signedXml = new SignedXml(clone);

        // Load the signature node.
        signedXml.LoadXml((XmlElement)signatures[i]);

        // Set the context for license transform
        Transform trans = ((Reference)signedXml.SignedInfo.References[0]).TransformChain[0];

        if (trans is XmlLicenseTransform)
        {

            // Decryptor is used to decrypt encryptedGrant elements.
            if (decryptor != null)
                (trans as XmlLicenseTransform).Decryptor = decryptor;
        }

        // Check the signature and display the result.
        bool result = signedXml.CheckSignature();

        if (result)
            Console.WriteLine("SUCCESS: CheckSignatureWithEncryptedGrant - issuer index #" +
                                            i.ToString());
        else
            Console.WriteLine("FAILURE: CheckSignatureWithEncryptedGrant - issuer index #" +
                                            i.ToString());
    }
}
    Public Shared Sub CheckSignatureWithEncryptedGrant(ByVal fileName As String, ByVal decryptor As IRelDecryptor)
        ' Create a new XML document.
        Dim xmlDocument As New XmlDocument()
        Dim nsManager As New XmlNamespaceManager(xmlDocument.NameTable)

        ' Format using white spaces.
        xmlDocument.PreserveWhitespace = True

        ' Load the passed XML file into the document. 
        xmlDocument.Load(fileName)
        nsManager.AddNamespace("dsig", SignedXml.XmlDsigNamespaceUrl)

        ' Find the "Signature" node and create a new XmlNodeList object.
        Dim nodeList As XmlNodeList = xmlDocument.SelectNodes("//dsig:Signature", nsManager)

        Dim count = nodeList.Count

        For i As Integer = 0 To count - 1
            Dim clone As XmlDocument = xmlDocument.Clone()
           
            Dim signatures As XmlNodeList = clone.SelectNodes("//dsig:Signature", nsManager)

            ' Create a new SignedXml object and pass into it the XML document clone.
            Dim signedXml As New SignedXml(clone)

            ' Load the signature node.
            signedXml.LoadXml(CType(signatures(i), XmlElement))

            ' Set the context for license transform
            Dim trans As Transform = CType(signedXml.SignedInfo.References(0), Reference).TransformChain(0)

            If TypeOf trans Is XmlLicenseTransform Then

                ' Decryptor is used to decrypt encryptedGrant elements.
                If Not (decryptor Is Nothing) Then
                    CType(trans, XmlLicenseTransform).Decryptor = decryptor
                End If

            End If

            ' Check the signature and display the result.
            Dim result As Boolean = signedXml.CheckSignature()

            If result Then
                Console.WriteLine("SUCCESS: CheckSignatureWithEncryptedGrant - issuer index #" + i.ToString())
            Else
                Console.WriteLine("FAILURE: CheckSignatureWithEncryptedGrant - issuer index #" + i.ToString())
            End If
        Next i

    End Sub
End Class

注解

XmlLicenseTransform 表示 MPEG 权限扩展语言 (MPEG REL) 中定义的许可证转换算法。

XmlLicenseTransform使用 类转换签名的 XrML 许可证。

描述 XmlLicenseTransform 类的统一资源标识符 (URI) 由 XmlLicenseTransformUrl 字段定义。

构造函数

XmlLicenseTransform()

初始化 XmlLicenseTransform 类的新实例。

属性

Algorithm

获取或设置用于标识当前转换所执行的算法的统一资源标识符 (URI)。

(继承自 Transform)
Context

获取或设置一个 XmlElement 对象,该对象表示当前 Transform 对象运行的文档上下文。

(继承自 Transform)
Decryptor

获取或设置当前 XmlLicenseTransform 对象的解密码。

InputTypes

获取一个类型数组,这些类型是当前 XmlLicenseTransform 对象的 OutputTypes 方法的有效输入。

OutputTypes

获取一个类型数组,这些类型是当前 XmlLicenseTransform 对象的 OutputTypes 方法的有效输出。

PropagatedNamespaces

获取或设置一个 Hashtable 对象,该对象包含传播到签名中的命名空间。

(继承自 Transform)
Resolver

设置当前的 XmlResolver 对象。

(继承自 Transform)

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetDigestedOutput(HashAlgorithm)

当在派生类中重写时,返回与 Transform 对象关联的摘要。

(继承自 Transform)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetInnerXml()

返回 XmlLicenseTransform 对象的参数的 XML 表示形式,适合以 XMLDSIG <Transform> 元素的子元素的形成来包含这些参数。

GetOutput()

返回 XmlLicenseTransform 对象的输出。

GetOutput(Type)

返回 XmlLicenseTransform 对象的输出。

GetType()

获取当前实例的 Type

(继承自 Object)
GetXml()

返回当前 Transform 对象的 XML 表示形式。

(继承自 Transform)
LoadInnerXml(XmlNodeList)

将指定的 XmlNodeList 对象分析为 <Transform> 元素的特定于转换的内容;此方法不受支持,因为 XmlLicenseTransform 对象没有内部 XML 元素。

LoadInput(Object)

将指定的输入加载到当前 XmlLicenseTransform 对象中。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于