語言

XmlLicenseTransform 類別

定義

代表用於標準化 XrML 授權簽章的授權轉換演算法。

public ref class XmlLicenseTransform : System::Security::Cryptography::Xml::Transform
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")]
public class XmlLicenseTransform : System.Security.Cryptography.Xml.Transform
public class XmlLicenseTransform : System.Security.Cryptography.Xml.Transform
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("XmlDsigXsltTransform uses XslCompiledTransform which requires dynamic code.")>]
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The algorithm implementations referenced in the XML payload might be removed. Ensure the required algorithm implementations are preserved in your application.")>]
type XmlLicenseTransform = class
    inherit Transform
type XmlLicenseTransform = class
    inherit Transform
Public Class XmlLicenseTransform
Inherits Transform
繼承
XmlLicenseTransform
屬性

範例

以下程式碼範例展示了如何利用介面 IRelDecryptor 與 XmlLicenseTransform 類別驗證 XML 數位簽章。

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 。

建構函式

名稱 Description
XmlLicenseTransform()

初始化 XmlLicenseTransform 類別的新執行個體。

屬性

名稱 Description
Algorithm

取得或設定統一資源識別碼(URI),用以識別電流轉換所執行的演算法。

(繼承來源 Transform)
Context

取得或設定一個 XmlElement 物件,代表該 Transform 物件目前執行的文件上下文。

(繼承來源 Transform)
Decryptor

取得或設定當前 XmlLicenseTransform 物件的解密器。

InputTypes

會得到一組類型,這些類型是當前 OutputTypes 物件方法 XmlLicenseTransform 的有效輸入。

OutputTypes

會得到一個由當前OutputTypes物件方法有效輸出XmlLicenseTransform的類型陣列。

PropagatedNamespaces

取得或設定一個 Hashtable 包含被傳播到簽名的命名空間的物件。

(繼承來源 Transform)
Resolver

設定目前的 XmlResolver 物件。

(繼承來源 Transform)

方法

名稱 Description
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetDigestedOutput(HashAlgorithm)

當在派生類別中覆寫時,會回傳與 Transform 物件相關的摘要。

(繼承來源 Transform)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetInnerXml()

回傳一個適合作為 XMLDSIG XmlLicenseTransform 元素子元素的物件參數<Transform>的 XML 表示。

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)

適用於