private static bool VerifyXml(XmlDocument Doc, AsynXmlCrypt.KeyManager Key)
{
if(Doc == null)
throw new ArgumentException(“xmlDoc”);
if (Key == null)
throw new ArgumentException(“key”);
// Create a new SignedXml object and pass it
// the XML document class.
SignedXml signedXml = new SignedXml(Doc);
// Find the "Signature" node and create a new
// XmlNodeList object.
XmlNodeList nodeList = Doc.GetElementsByTagName("Signature");
// Throw an exception if no signature was found.
if (nodeList.Count <= 0)
{
throw new CryptographicException("Verification failed: No Signature was found in the document.");
}
// This example only supports one signature for
// the entire XML document. Throw an exception
// if more than one signature was found.
if (nodeList.Count >= 2)
{
throw new CryptographicException("Verification failed: More that one signature was found for the document.");
}
// Load the first <signature> node.
signedXml.LoadXml((XmlElement)nodeList[0]);
// Check the signature and return the result.
return signedXml.CheckSignature(Key);
}
Estou trabalhando com assinatura digital e gostaria de checar se assinatura está válida. Porém quando eu retorno ( return
signedXml.CheckSignature(Key);fala que não é possível de converter de AsynXmlCrypt.KeyManager para System.Security.Cryptograpnhy.AsymetricAlgorithm.
E com isso a minha assinatura passa como invalida pois não consigo retorna lá para está função
try
{
Console.WriteLine(“Verifying signature…”);
bool result = VerifyXml(Doc, 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 (Exception e)
{
Console.WriteLine(e.Message);
}