SignedXml 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
XML 서명을 쉽게 만들도록 하기 위해 핵심 XML 서명 개체에 래퍼를 제공합니다.
public ref class SignedXml
public class SignedXml
type SignedXml = class
Public Class SignedXml
- 상속
-
SignedXml
예제
다음 코드 예제에서는 봉투 서명을 사용하여 전체 XML 문서에 서명하고 확인하는 방법을 보여줍니다.
//
// This example signs an XML file using an
// envelope signature. It then verifies the
// signed XML.
//
#using <System.Security.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::X509Certificates;
using namespace System::Security::Cryptography::Xml;
using namespace System::Text;
using namespace System::Xml;
// Sign an XML file and save the signature in a new file. This method does not
// save the public key within the XML file. This file cannot be verified unless
// the verifying code has the key with which it was signed.
void SignXmlFile( String^ FileName, String^ SignedFileName, RSA^ Key )
{
// Create a new XML document.
XmlDocument^ doc = gcnew XmlDocument;
// Load the passed XML file using its name.
doc->Load( gcnew XmlTextReader( FileName ) );
// Create a SignedXml object.
SignedXml^ signedXml = gcnew SignedXml( doc );
// Add the key to the SignedXml document.
signedXml->SigningKey = Key;
// Create a reference to be signed.
Reference^ reference = gcnew Reference;
reference->Uri = "";
// Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform^ env = gcnew XmlDsigEnvelopedSignatureTransform;
reference->AddTransform( env );
// Add the reference to the SignedXml object.
signedXml->AddReference( reference );
// Compute the signature.
signedXml->ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement^ xmlDigitalSignature = signedXml->GetXml();
// Append the element to the XML document.
doc->DocumentElement->AppendChild( doc->ImportNode( xmlDigitalSignature, true ) );
if ( (doc->FirstChild)->GetType() == XmlDeclaration::typeid )
{
doc->RemoveChild( doc->FirstChild );
}
// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter^ xmltw = gcnew XmlTextWriter( SignedFileName,gcnew UTF8Encoding( false ) );
doc->WriteTo( xmltw );
xmltw->Close();
}
// Verify the signature of an XML file against an asymmetric
// algorithm and return the result.
Boolean VerifyXmlFile( String^ Name, RSA^ Key )
{
// Create a new XML document.
XmlDocument^ xmlDocument = gcnew XmlDocument;
// Load the passed XML file into the document.
xmlDocument->Load( Name );
// Create a new SignedXml object and pass it
// the XML document class.
SignedXml^ signedXml = gcnew SignedXml( xmlDocument );
// Find the "Signature" node and create a new
// XmlNodeList object.
XmlNodeList^ nodeList = xmlDocument->GetElementsByTagName( "Signature" );
// Load the signature node.
signedXml->LoadXml( safe_cast<XmlElement^>(nodeList->Item( 0 )) );
// Check the signature and return the result.
return signedXml->CheckSignature( Key );
}
// Create example data to sign.
void CreateSomeXml( String^ FileName )
{
// Create a new XmlDocument Object*.
XmlDocument^ document = gcnew XmlDocument;
// Create a new XmlNode object.
XmlNode^ node = document->CreateNode( XmlNodeType::Element, "", "MyElement", "samples" );
// Add some text to the node.
node->InnerText = "Example text to be signed.";
// Append the node to the document.
document->AppendChild( node );
// Save the XML document to the file name specified.
XmlTextWriter^ xmltw = gcnew XmlTextWriter( FileName,gcnew UTF8Encoding( false ) );
document->WriteTo( xmltw );
xmltw->Close();
}
int main()
{
try
{
// Generate a signing key.
RSA^ Key = RSA::Create();
// Create an XML file to sign.
CreateSomeXml( "Example.xml" );
Console::WriteLine( "New XML file created." );
// Sign the XML that was just created and save it in a
// new file.
SignXmlFile( "Example.xml", "signedExample.xml", Key );
Console::WriteLine( "XML file signed." );
// Verify the signature of the signed XML.
Console::WriteLine( "Verifying signature..." );
bool result = VerifyXmlFile( "SignedExample.xml", Key );
// Display the results of the signature verification to
// the console.
if ( result )
{
Console::WriteLine( "The XML signature is valid." );
}
else
{
Console::WriteLine( "The XML signature is not valid." );
}
}
catch ( CryptographicException^ e )
{
Console::WriteLine( e->Message );
}
}
//
// This example signs an XML file using an
// envelope signature. It then verifies the
// signed XML.
//
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Xml;
public class SignVerifyEnvelope
{
public static void Main(String[] args)
{
try
{
// Generate a signing key.
RSA Key = RSA.Create();
// Create an XML file to sign.
CreateSomeXml("Example.xml");
Console.WriteLine("New XML file created.");
// Sign the XML that was just created and save it in a
// new file.
SignXmlFile("Example.xml", "signedExample.xml", Key);
Console.WriteLine("XML file signed.");
// Verify the signature of the signed XML.
Console.WriteLine("Verifying signature...");
bool result = VerifyXmlFile("SignedExample.xml", Key);
// Display the results of the signature verification to
// the console.
if(result)
{
Console.WriteLine("The XML signature is valid.");
}
else
{
Console.WriteLine("The XML signature is not valid.");
}
}
catch(CryptographicException e)
{
Console.WriteLine(e.Message);
}
}
// Sign an XML file and save the signature in a new file. This method does not
// save the public key within the XML file. This file cannot be verified unless
// the verifying code has the key with which it was signed.
public static void SignXmlFile(string FileName, string SignedFileName, RSA Key)
{
// Create a new XML document.
XmlDocument doc = new XmlDocument();
// Load the passed XML file using its name.
doc.Load(new XmlTextReader(FileName));
// Create a SignedXml object.
SignedXml signedXml = new SignedXml(doc);
// Add the key to the SignedXml document.
signedXml.SigningKey = Key;
// Create a reference to be signed.
Reference reference = new Reference();
reference.Uri = "";
// Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
// Add the reference to the SignedXml object.
signedXml.AddReference(reference);
// Compute the signature.
signedXml.ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSignature = signedXml.GetXml();
// Append the element to the XML document.
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
if (doc.FirstChild is XmlDeclaration)
{
doc.RemoveChild(doc.FirstChild);
}
// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new UTF8Encoding(false));
doc.WriteTo(xmltw);
xmltw.Close();
}
// Verify the signature of an XML file against an asymmetric
// algorithm and return the result.
public static Boolean VerifyXmlFile(String Name, RSA Key)
{
// Create a new XML document.
XmlDocument xmlDocument = new XmlDocument();
// Load the passed XML file into the document.
xmlDocument.Load(Name);
// Create a new SignedXml object and pass it
// the XML document class.
SignedXml signedXml = new SignedXml(xmlDocument);
// Find the "Signature" node and create a new
// XmlNodeList object.
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
// Load the signature node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// Check the signature and return the result.
return signedXml.CheckSignature(Key);
}
// Create example data to sign.
public static void CreateSomeXml(string FileName)
{
// Create a new XmlDocument object.
XmlDocument document = new XmlDocument();
// Create a new XmlNode object.
XmlNode node = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples");
// Add some text to the node.
node.InnerText = "Example text to be signed.";
// Append the node to the document.
document.AppendChild(node);
// Save the XML document to the file name specified.
XmlTextWriter xmltw = new XmlTextWriter(FileName, new UTF8Encoding(false));
document.WriteTo(xmltw);
xmltw.Close();
}
}
'
' This example signs an XML file using an
' envelope signature. It then verifies the
' signed XML.
'
Imports System.Security.Cryptography
Imports System.Security.Cryptography.X509Certificates
Imports System.Security.Cryptography.Xml
Imports System.Text
Imports System.Xml
Public Class SignVerifyEnvelope
Overloads Public Shared Sub Main(args() As [String])
Try
' Generate a signing key.
Dim Key As RSA = RSA.Create()
' Create an XML file to sign.
CreateSomeXml("Example.xml")
Console.WriteLine("New XML file created.")
' Sign the XML that was just created and save it in a
' new file.
SignXmlFile("Example.xml", "signedExample.xml", Key)
Console.WriteLine("XML file signed.")
' Verify the signature of the signed XML.
Console.WriteLine("Verifying signature...")
Dim result As Boolean = VerifyXmlFile("SignedExample.xml", Key)
' Display the results of the signature verification to
' the console.
If result Then
Console.WriteLine("The XML signature is valid.")
Else
Console.WriteLine("The XML signature is not valid.")
End If
Catch e As CryptographicException
Console.WriteLine(e.Message)
End Try
End Sub
' Sign an XML file and save the signature in a new file. This method does not
' save the public key within the XML file. This file cannot be verified unless
' the verifying code has the key with which it was signed.
Public Shared Sub SignXmlFile(FileName As String, SignedFileName As String, Key As RSA)
' Create a new XML document.
Dim doc As New XmlDocument()
' Load the passed XML file using its name.
doc.Load(New XmlTextReader(FileName))
' Create a SignedXml object.
Dim signedXml As New SignedXml(doc)
' Add the key to the SignedXml document.
signedXml.SigningKey = Key
' Create a reference to be signed.
Dim reference As New Reference()
reference.Uri = ""
' Add an enveloped transformation to the reference.
Dim env As New XmlDsigEnvelopedSignatureTransform()
reference.AddTransform(env)
' Add the reference to the SignedXml object.
signedXml.AddReference(reference)
' Compute the signature.
signedXml.ComputeSignature()
' Get the XML representation of the signature and save
' it to an XmlElement object.
Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()
' Append the element to the XML document.
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, True))
If TypeOf doc.FirstChild Is XmlDeclaration Then
doc.RemoveChild(doc.FirstChild)
End If
' Save the signed XML document to a file specified
' using the passed string.
Dim xmltw As New XmlTextWriter(SignedFileName, New UTF8Encoding(False))
doc.WriteTo(xmltw)
xmltw.Close()
End Sub
' Verify the signature of an XML file against an asymmetric
' algorithm and return the result.
Public Shared Function VerifyXmlFile(Name As [String], Key As RSA) As [Boolean]
' Create a new XML document.
Dim xmlDocument As New XmlDocument()
' Load the passed XML file into the document.
xmlDocument.Load(Name)
' Create a new SignedXml object and pass it
' the XML document class.
Dim signedXml As New SignedXml(xmlDocument)
' Find the "Signature" node and create a new
' XmlNodeList object.
Dim nodeList As XmlNodeList = xmlDocument.GetElementsByTagName("Signature")
' Load the signature node.
signedXml.LoadXml(CType(nodeList(0), XmlElement))
' Check the signature and return the result.
Return signedXml.CheckSignature(Key)
End Function
' Create example data to sign.
Public Shared Sub CreateSomeXml(FileName As String)
' Create a new XmlDocument object.
Dim document As New XmlDocument()
' Create a new XmlNode object.
Dim node As XmlNode = document.CreateNode(XmlNodeType.Element, "", "MyElement", "samples")
' Add some text to the node.
node.InnerText = "Example text to be signed."
' Append the node to the document.
document.AppendChild(node)
' Save the XML document to the file name specified.
Dim xmltw As New XmlTextWriter(FileName, New UTF8Encoding(False))
document.WriteTo(xmltw)
xmltw.Close()
End Sub
End Class
다음 코드 예제에서는 인벨로핑 서명을 사용하여 XML 문서의 단일 요소에 서명하고 확인하는 방법을 보여줍니다.
//
// This example signs an XML file using an
// envelope signature. It then verifies the
// signed XML.
//
#using <System.Xml.dll>
#using <System.Security.dll>
#using <System.dll>
using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Cryptography::Xml;
using namespace System::Text;
using namespace System::Xml;
// Sign an XML file and save the signature in a new file.
static void SignXmlFile( String^ FileName, String^ SignedFileName, RSA^ Key, array<String^>^ElementsToSign )
{
// Check the arguments.
if ( FileName == nullptr )
throw gcnew ArgumentNullException( L"FileName" );
if ( SignedFileName == nullptr )
throw gcnew ArgumentNullException( L"SignedFileName" );
if ( Key == nullptr )
throw gcnew ArgumentNullException( L"Key" );
if ( ElementsToSign == nullptr )
throw gcnew ArgumentNullException( L"ElementsToSign" );
// Create a new XML document.
XmlDocument^ doc = gcnew XmlDocument;
// Format the document to ignore white spaces.
doc->PreserveWhitespace = false;
// Load the passed XML file using it's name.
doc->Load( gcnew XmlTextReader( FileName ) );
// Create a SignedXml object.
SignedXml^ signedXml = gcnew SignedXml( doc );
// Add the key to the SignedXml document.
signedXml->SigningKey = Key;
// Loop through each passed element to sign
// and create a reference.
System::Collections::IEnumerator^ myEnum = ElementsToSign->GetEnumerator();
while ( myEnum->MoveNext() )
{
String^ s = safe_cast<String^>(myEnum->Current);
// Create a reference to be signed.
Reference^ reference = gcnew Reference;
reference->Uri = s;
// Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform^ env = gcnew XmlDsigEnvelopedSignatureTransform;
reference->AddTransform( env );
// Add the reference to the SignedXml object.
signedXml->AddReference( reference );
}
// Add an RSAKeyValue KeyInfo (optional; helps recipient find key to validate).
KeyInfo^ keyInfo = gcnew KeyInfo;
keyInfo->AddClause( gcnew RSAKeyValue( dynamic_cast<RSA^>(Key) ) );
signedXml->KeyInfo = keyInfo;
// Compute the signature.
signedXml->ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement^ xmlDigitalSignature = signedXml->GetXml();
// Append the element to the XML document.
doc->DocumentElement->AppendChild( doc->ImportNode( xmlDigitalSignature, true ) );
if ( dynamic_cast<XmlDeclaration^>(doc->FirstChild) )
{
doc->RemoveChild( doc->FirstChild );
}
// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter^ xmltw = gcnew XmlTextWriter( SignedFileName,gcnew UTF8Encoding( false ) );
doc->WriteTo( xmltw );
xmltw->Close();
}
// Verify the signature of an XML file and return the result.
static Boolean VerifyXmlFile( String^ Name )
{
// Check the arguments.
if ( Name == nullptr )
throw gcnew ArgumentNullException( L"Name" );
// Create a new XML document.
XmlDocument^ xmlDocument = gcnew XmlDocument;
// Format using white spaces.
xmlDocument->PreserveWhitespace = true;
// Load the passed XML file into the document.
xmlDocument->Load( Name );
// Create a new SignedXml object and pass it
// the XML document class.
SignedXml^ signedXml = gcnew SignedXml( xmlDocument );
// Find the "Signature" node and create a new
// XmlNodeList object.
XmlNodeList^ nodeList = xmlDocument->GetElementsByTagName( L"Signature" );
// Load the signature node.
signedXml->LoadXml( dynamic_cast<XmlElement^>(nodeList->Item( 0 )) );
// Check the signature and return the result.
return signedXml->CheckSignature();
}
int main()
{
// Generate a signing key.
RSA^ Key = RSA::Create();
try
{
// Specify an element to sign.
array<String^>^elements = {L"#tag1"};
// Sign an XML file and save the signature to a
// new file.
SignXmlFile( L"Test.xml", L"SignedExample.xml", Key, elements );
Console::WriteLine( L"XML file signed." );
// Verify the signature of the signed XML.
Console::WriteLine( L"Verifying signature..." );
bool result = VerifyXmlFile( L"SignedExample.xml" );
// Display the results of the signature verification to
// the console.
if ( result )
{
Console::WriteLine( L"The XML signature is valid." );
}
else
{
Console::WriteLine( L"The XML signature is not valid." );
}
}
catch ( CryptographicException^ e )
{
Console::WriteLine( e->Message );
}
finally
{
// Clear resources associated with the
// RSA instance.
Key->Clear();
}
return 1;
}
//
// This example signs an XML file using an
// envelope signature. It then verifies the
// signed XML.
//
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Xml;
public class SignVerifyEnvelope
{
public static void Main(String[] args)
{
// Generate a signing key.
RSA Key = RSA.Create();
try
{
// Specify an element to sign.
string[] elements = { "#tag1" };
// Sign an XML file and save the signature to a
// new file.
SignXmlFile("Test.xml", "SignedExample.xml", Key, elements);
Console.WriteLine("XML file signed.");
// Verify the signature of the signed XML.
Console.WriteLine("Verifying signature...");
bool result = VerifyXmlFile("SignedExample.xml");
// Display the results of the signature verification to
// the console.
if (result)
{
Console.WriteLine("The XML signature is valid.");
}
else
{
Console.WriteLine("The XML signature is not valid.");
}
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
}
finally
{
// Clear resources associated with the
// RSA instance.
Key.Clear();
}
}
// Sign an XML file and save the signature in a new file.
public static void SignXmlFile(string FileName, string SignedFileName, RSA Key, string[] ElementsToSign)
{
// Check the arguments.
if (FileName == null)
throw new ArgumentNullException("FileName");
if (SignedFileName == null)
throw new ArgumentNullException("SignedFileName");
if (Key == null)
throw new ArgumentNullException("Key");
if (ElementsToSign == null)
throw new ArgumentNullException("ElementsToSign");
// Create a new XML document.
XmlDocument doc = new XmlDocument();
// Format the document to ignore white spaces.
doc.PreserveWhitespace = false;
// Load the passed XML file using it's name.
doc.Load(new XmlTextReader(FileName));
// Create a SignedXml object.
SignedXml signedXml = new SignedXml(doc);
// Add the key to the SignedXml document.
signedXml.SigningKey = Key;
// Loop through each passed element to sign
// and create a reference.
foreach (string s in ElementsToSign)
{
// Create a reference to be signed.
Reference reference = new Reference();
reference.Uri = s;
// Add an enveloped transformation to the reference.
XmlDsigEnvelopedSignatureTransform env = new XmlDsigEnvelopedSignatureTransform();
reference.AddTransform(env);
// Add the reference to the SignedXml object.
signedXml.AddReference(reference);
}
// Add an RSAKeyValue KeyInfo (optional; helps recipient find key to validate).
KeyInfo keyInfo = new KeyInfo();
keyInfo.AddClause(new RSAKeyValue((RSA)Key));
signedXml.KeyInfo = keyInfo;
// Compute the signature.
signedXml.ComputeSignature();
// Get the XML representation of the signature and save
// it to an XmlElement object.
XmlElement xmlDigitalSignature = signedXml.GetXml();
// Append the element to the XML document.
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
if (doc.FirstChild is XmlDeclaration)
{
doc.RemoveChild(doc.FirstChild);
}
// Save the signed XML document to a file specified
// using the passed string.
XmlTextWriter xmltw = new XmlTextWriter(SignedFileName, new UTF8Encoding(false));
doc.WriteTo(xmltw);
xmltw.Close();
}
// Verify the signature of an XML file and return the result.
public static Boolean VerifyXmlFile(String Name)
{
// Check the arguments.
if (Name == null)
throw new ArgumentNullException("Name");
// Create a new XML document.
XmlDocument xmlDocument = new XmlDocument();
// Format using white spaces.
xmlDocument.PreserveWhitespace = true;
// Load the passed XML file into the document.
xmlDocument.Load(Name);
// Create a new SignedXml object and pass it
// the XML document class.
SignedXml signedXml = new SignedXml(xmlDocument);
// Find the "Signature" node and create a new
// XmlNodeList object.
XmlNodeList nodeList = xmlDocument.GetElementsByTagName("Signature");
// Load the signature node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// Check the signature and return the result.
return signedXml.CheckSignature();
}
}
' This example signs an XML file using an
' envelope signature. It then verifies the
' signed XML.
'
Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml
Imports System.Text
Imports System.Xml
Module SignVerifyEnvelope
Sub Main(ByVal args() As String)
' Generate a signing key.
Dim Key As RSA = RSA.Create()
Try
' Specify an element to sign.
Dim elements As String() = New String() {"#tag1"}
' Sign an XML file and save the signature to a
' new file.
SignXmlFile("Test.xml", "SignedExample.xml", Key, elements)
Console.WriteLine("XML file signed.")
' Verify the signature of the signed XML.
Console.WriteLine("Verifying signature...")
Dim result As Boolean = VerifyXmlFile("SignedExample.xml")
' Display the results of the signature verification to \
' the console.
If result Then
Console.WriteLine("The XML signature is valid.")
Else
Console.WriteLine("The XML signature is not valid.")
End If
Catch e As CryptographicException
Console.WriteLine(e.Message)
Finally
' Clear resources associated with the
' RSA instance.
Key.Clear()
End Try
End Sub
' Sign an XML file and save the signature in a new file.
Sub SignXmlFile(ByVal FileName As String, ByVal SignedFileName As String, ByVal Key As RSA, ByVal ElementsToSign() As String)
' Check the arguments.
If FileName Is Nothing Then
Throw New ArgumentNullException("FileName")
End If
If SignedFileName Is Nothing Then
Throw New ArgumentNullException("SignedFileName")
End If
If Key Is Nothing Then
Throw New ArgumentNullException("Key")
End If
If ElementsToSign Is Nothing Then
Throw New ArgumentNullException("ElementsToSign")
End If
' Create a new XML document.
Dim doc As New XmlDocument()
' Format the document to ignore white spaces.
doc.PreserveWhitespace = False
' Load the passed XML file using it's name.
doc.Load(New XmlTextReader(FileName))
' Create a SignedXml object.
Dim signedXml As New SignedXml(doc)
' Add the key to the SignedXml document.
signedXml.SigningKey = Key
' Loop through each passed element to sign
' and create a reference.
Dim s As String
For Each s In ElementsToSign
' Create a reference to be signed.
Dim reference As New Reference()
reference.Uri = s
' Add an enveloped transformation to the reference.
Dim env As New XmlDsigEnvelopedSignatureTransform()
reference.AddTransform(env)
' Add the reference to the SignedXml object.
signedXml.AddReference(reference)
Next s
' Add an RSAKeyValue KeyInfo (optional; helps recipient find key to validate).
Dim keyInfo As New KeyInfo()
keyInfo.AddClause(New RSAKeyValue(CType(Key, RSA)))
signedXml.KeyInfo = keyInfo
' Compute the signature.
signedXml.ComputeSignature()
' Get the XML representation of the signature and save
' it to an XmlElement object.
Dim xmlDigitalSignature As XmlElement = signedXml.GetXml()
' Append the element to the XML document.
doc.DocumentElement.AppendChild(doc.ImportNode(xmlDigitalSignature, True))
If TypeOf doc.FirstChild Is XmlDeclaration Then
doc.RemoveChild(doc.FirstChild)
End If
' Save the signed XML document to a file specified
' using the passed string.
Dim xmltw As New XmlTextWriter(SignedFileName, New UTF8Encoding(False))
doc.WriteTo(xmltw)
xmltw.Close()
End Sub
' Verify the signature of an XML file and return the result.
Function VerifyXmlFile(ByVal Name As String) As [Boolean]
' Check the arguments.
If Name Is Nothing Then
Throw New ArgumentNullException("Name")
End If
' Create a new XML document.
Dim xmlDocument As New XmlDocument()
' Format using white spaces.
xmlDocument.PreserveWhitespace = True
' Load the passed XML file into the document.
xmlDocument.Load(Name)
' Create a new SignedXml object and pass it
' the XML document class.
Dim signedXml As New SignedXml(xmlDocument)
' Find the "Signature" node and create a new
' XmlNodeList object.
Dim nodeList As XmlNodeList = xmlDocument.GetElementsByTagName("Signature")
' Load the signature node.
signedXml.LoadXml(CType(nodeList(0), XmlElement))
' Check the signature and return the result.
Return signedXml.CheckSignature()
End Function
End Module
설명
이 API에 대한 자세한 내용은 SignedXml에 대한 추가 API 설명을 참조하세요.
생성자
SignedXml() |
SignedXml 클래스의 새 인스턴스를 초기화합니다. |
SignedXml(XmlDocument) |
지정된 XML 문서에서 SignedXml 클래스의 새 인스턴스를 초기화합니다. |
SignedXml(XmlElement) |
지정된 SignedXml 개체에서 XmlElement 클래스의 새 인스턴스를 초기화합니다. |
필드
m_signature | |
m_strSigningKeyName |
SignedXml 개체 서명에 사용할 설치된 키의 이름을 나타냅니다. |
XmlDecryptionTransformUrl |
XML 모드 해독 변환에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigBase64TransformUrl |
Base 64 변환에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigC14NTransformUrl |
정규 XML 변환에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigC14NWithCommentsTransformUrl |
설명이 있는 정규 XML 변환에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigCanonicalizationUrl |
XML 디지털 서명을 위한 표준 정규화 알고리즘에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigCanonicalizationWithCommentsUrl |
XML 디지털 서명을 위한 표준 정규화 알고리즘에 대한 URI(Uniform Resource Identifier)를 나타내고 설명을 포함합니다. 이 필드는 상수입니다. |
XmlDsigDSAUrl |
XML 디지털 서명을 위한 표준 DSA 알고리즘에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigEnvelopedSignatureTransformUrl |
엔벌로프된 서명 변환에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigExcC14NTransformUrl |
배타적 XML 정규화에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigExcC14NWithCommentsTransformUrl |
설명이 있는 배타적 XML 정규화에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigHMACSHA1Url |
XML 디지털 서명을 위한 표준 HMACSHA1 알고리즘에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigMinimalCanonicalizationUrl |
XML 디지털 서명을 위한 최소 표준 정규화 알고리즘에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigNamespaceUrl |
XML 디지털 서명을 위한 표준 네임스페이스에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigRSASHA1Url |
XML 디지털 서명을 위한 표준 RSA 서명 메서드에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigRSASHA256Url |
XML 디지털 서명에 대한 SHA-256 서명 방법 변형에 RSA 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigRSASHA384Url |
XML 디지털 서명에 대한 SHA-384 서명 방법 변형에 대한 RSA URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigRSASHA512Url |
XML 디지털 서명에 대한 SHA-512 서명 방법 변형에 RSA 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigSHA1Url |
XML 디지털 서명을 위한 표준 SHA1 다이제스트 방법에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigSHA256Url |
XML 디지털 서명을 위한 표준 SHA256 다이제스트 방법에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigSHA384Url |
XML 디지털 서명을 위한 표준 SHA384 다이제스트 방법에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigSHA512Url |
XML 디지털 서명을 위한 표준 SHA512 다이제스트 방법에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigXPathTransformUrl |
XPath(XML Path Language)에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlDsigXsltTransformUrl |
XSLT 변환에 대한 URI(Uniform Resource Identifier)를 나타냅니다. 이 필드는 상수입니다. |
XmlLicenseTransformUrl |
서명을 위해 XrML 라이선스를 정규화하는 데 사용할 라이선스 변환 알고리즘에 대한 URI(Uniform Resource Identifier)를 나타냅니다. |
속성
EncryptedXml |
XML 암호화 처리 규칙을 정의하는 EncryptedXml 개체를 가져오거나 설정합니다. |
KeyInfo | |
Resolver |
현재의 XmlResolver 개체를 설정합니다. |
SafeCanonicalizationMethods |
정규화 알고리즘이 명시적으로 허용되는 메서드의 이름을 가져옵니다. |
Signature | |
SignatureFormatValidator |
XML 서명의 서식(암호화 보안 아님) 유효성을 검사하기 위해 호출할 대리자를 가져옵니다. |
SignatureLength |
현재 SignedXml 개체의 서명 길이를 가져옵니다. |
SignatureMethod |
현재 SignedXml 개체의 서명 메서드를 가져옵니다. |
SignatureValue |
현재 SignedXml 개체의 서명 값을 가져옵니다. |
SignedInfo |
현재 SignedInfo 개체의 SignedXml 개체를 가져옵니다. |
SigningKey |
SignedXml 개체 서명에 사용된 비대칭 알고리즘 키를 가져오거나 설정합니다. |
SigningKeyName |
SignedXml 개체 서명에 사용할 설치된 키의 이름을 가져오거나 설정합니다. |
메서드
AddObject(DataObject) |
서명할 개체 목록에 DataObject 개체를 추가합니다. |
AddReference(Reference) |
Reference 개체를 SignedXml 개체에 추가하여 XML 디지털 서명을 만드는 데 사용할 다이제스트 메서드, 다이제스트 값 및 변환을 설명합니다. |
CheckSignature() |
Signature 속성이 서명에 공개 키 사용을 확인하는지 여부를 결정합니다. |
CheckSignature(AsymmetricAlgorithm) |
Signature 속성이 지정된 키를 확인하는지 여부를 결정합니다. |
CheckSignature(KeyedHashAlgorithm) |
Signature 속성이 지정된 MAC(메시지 인증 코드) 알고리즘을 확인하는지 여부를 결정합니다. |
CheckSignature(X509Certificate2, Boolean) |
Signature 속성이 지정된 X509Certificate2 개체를 확인하는지 여부를 결정하고, 선택적으로 인증서가 유효한지 여부도 결정합니다. |
CheckSignatureReturningKey(AsymmetricAlgorithm) |
Signature 속성이 서명에 공개 키 사용을 확인하는지 여부를 결정합니다. |
ComputeSignature() |
XML 디지털 서명을 계산합니다. |
ComputeSignature(KeyedHashAlgorithm) |
지정된 MAC(메시지 인증 코드) 알고리즘을 사용하여 XML 디지털 서명을 계산합니다. |
Equals(Object) |
지정된 개체가 현재 개체와 같은지 확인합니다. (다음에서 상속됨 Object) |
GetHashCode() |
기본 해시 함수로 작동합니다. (다음에서 상속됨 Object) |
GetIdElement(XmlDocument, String) |
지정된 XmlElement 개체에서 지정된 ID를 가진 XmlDocument 개체를 반환합니다. |
GetPublicKey() |
서명의 공개 키를 반환합니다. |
GetType() |
현재 인스턴스의 Type을 가져옵니다. (다음에서 상속됨 Object) |
GetXml() |
SignedXml 개체의 XML 표현을 반환합니다. |
LoadXml(XmlElement) |
XML 요소에서 SignedXml 상태를 로드합니다. |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
적용 대상
추가 정보
.NET