次の方法で共有


SignedXml.CheckSignature メソッド ()

Signature が署名内の公開キーを使用して検証するかどうかを判断します。

Overloads Public Function CheckSignature() As Boolean
[C#]
public bool CheckSignature();
[C++]
public: bool CheckSignature();
[JScript]
public function CheckSignature() : Boolean;

戻り値

Signature が検証する場合は true 。それ以外の場合は false

例外

例外の種類 条件
CryptographicException 署名内の公開キーの SignatureAlgorithm が、 SignatureMethod プロパティと一致しません。

または

署名の説明を作成できませんでした。

または

ハッシュ アルゴリズムを作成できませんでした。

解説

このメソッドは、参照のダイジェストと署名の値も計算します。

使用例

 
' Verify the signature of an XML file and return the result.
Public Shared Function VerifyDetachedSignature(XmlSigFileName As String) As [Boolean]
   ' Create a new XML document.
   Dim xmlDocument As New XmlDocument()
   
   ' Load the passed XML file into the document.
   xmlDocument.Load(XmlSigFileName)
   
   ' Create a new SignedXMl object.
   Dim signedXml As New SignedXml()
   
   ' 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

[C#] 
// Verify the signature of an XML file and return the result.
public static Boolean VerifyDetachedSignature(string XmlSigFileName)
{    
    // Create a new XML document.
    XmlDocument xmlDocument = new XmlDocument();

    // Load the passed XML file into the document.
    xmlDocument.Load(XmlSigFileName);

    // Create a new SignedXMl object.
    SignedXml signedXml = new SignedXml();

    // 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();
}

[C++] 
// Verify the signature of an XML file and return the result.
Boolean VerifyDetachedSignature(String* XmlSigFileName) {    
   // Create a new XML document.
   XmlDocument* xmlDocument = new XmlDocument();

   // Load the passed XML file into the document.
   xmlDocument->Load(XmlSigFileName);

   // Create a new SignedXMl object.
   SignedXml* signedXml = new SignedXml();

   // Find the "Signature" node and create a new
   // XmlNodeList object.
   XmlNodeList* nodeList = xmlDocument->GetElementsByTagName(S"Signature");

   // Load the signature node.
   signedXml->LoadXml(__try_cast<XmlElement*>( nodeList->Item(0) ));

   // Check the signature and return the result.
   return signedXml->CheckSignature();
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

.NET Framework セキュリティ:

参照

SignedXml クラス | SignedXml メンバ | System.Security.Cryptography.Xml 名前空間 | SignedXml.CheckSignature オーバーロードの一覧