XmlLicenseTransform 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示用來正規化簽章 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 類別來驗證 XML 數位簽章 IRelDecryptor 。
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 Rights Extension Language (MPEG REL) 中所定義的授權轉換演算法。
XmlLicenseTransform使用 類別來轉換簽章的 XrML 授權。
描述 XmlLicenseTransform 類別的統一資源識別元 (URI) 是由 欄位定義 XmlLicenseTransformUrl 。
建構函式
XmlLicenseTransform() |
初始化 XmlLicenseTransform 類別的新執行個體。 |
屬性
Algorithm |
取得或設定統一資源識別元 (URI),它識別了目前轉換所執行的演算法。 (繼承來源 Transform) |
Context |
取得或設定 XmlElement 物件,表示目前 Transform 物件在其下執行的文件內容。 (繼承來源 Transform) |
Decryptor |
取得或設定目前 XmlLicenseTransform 的解密子。 |
InputTypes |
取得型別陣列,其為目前 OutputTypes 物件之 XmlLicenseTransform 方法的有效輸入。 |
OutputTypes |
取得可以從目前 OutputTypes 物件的 XmlLicenseTransform 方法有效輸出的型別陣列。 |
PropagatedNamespaces |
取得或設定 Hashtable 物件,內含傳送至簽章的命名空間。 (繼承來源 Transform) |
Resolver |
設定目前的 XmlResolver 物件。 (繼承來源 Transform) |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetDigestedOutput(HashAlgorithm) |
在衍生類別中覆寫時,傳回與 Transform 物件關聯的摘要。 (繼承來源 Transform) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetInnerXml() |
傳回 XmlLicenseTransform 物件參數的 XML 表示,此物件適合納入為 XMLDSIG |
GetOutput() |
傳回 XmlLicenseTransform 物件的輸出。 |
GetOutput(Type) |
傳回 XmlLicenseTransform 物件的輸出。 |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
GetXml() |
傳回目前 Transform 物件的 XML 表示。 (繼承來源 Transform) |
LoadInnerXml(XmlNodeList) |
將指定的 XmlNodeList 物件剖析為 |
LoadInput(Object) |
將指定的輸入載入目前的 XmlLicenseTransform 物件。 |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |