public virtual bool CheckSameCertificate()
{
bool retVal = false;
//KeyInfoX509Data keyInfoX509Data = new KeyInfoX509Data();
//keyInfoX509Data.LoadXml(this.KeyInfo.GetXml());
//if (keyInfoX509Data.Certificates.Count <= 0)
//{
// throw new CryptographicException("Certificate not found in XMLDSIG signature while doing CheckSameCertificate()");
//}
//string xmldsigCertHash = Convert.ToBase64String(((X509Certificate)keyInfoX509Data.Certificates[0]).GetCertHash());
X509Certificate xmldsigCert = new X509Certificate(System.Text.Encoding.ASCII.GetBytes(this.KeyInfo.GetXml().InnerText));
string xmldsigCertHash = Convert.ToBase64String(xmldsigCert.GetCertHash());
CertCollection xadesSigningCertificateCollection = this.XadesObject.QualifyingProperties.SignedProperties.SignedSignatureProperties.SigningCertificate.CertCollection;
if (xadesSigningCertificateCollection.Count <= 0)
{
throw new CryptographicException("Certificate not found in SigningCertificate element while doing CheckSameCertificate()");
}
string xadesCertHash = Convert.ToBase64String(((Cert)xadesSigningCertificateCollection[0]).CertDigest.DigestValue);
if (String.Compare(xmldsigCertHash, xadesCertHash, true, CultureInfo.InvariantCulture) != 0)
{
throw new CryptographicException("Certificate in XMLDSIG signature doesn't match certificate in SigningCertificate element");
}
retVal = true;
return retVal;
}