private bool Match(
X509Certificate2 certificate,
string subjectName,
string serialNumber,
string authorityKeyId)
{
// check for null.
if (certificate == null)
{
return false;
}
// check for subject name match.
if (!Utils.CompareDistinguishedName(certificate.SubjectName.Name, subjectName))
{
return false;
}
// check for serial number match.
if (!String.IsNullOrEmpty(serialNumber))
{
if (certificate.SerialNumber != serialNumber)
{
return false;
}
}
// check for authority key id match.
if (!String.IsNullOrEmpty(authorityKeyId))
{
X509SubjectKeyIdentifierExtension subjectKeyId = FindSubjectKeyIdentifierExtension(certificate);
if (subjectKeyId != null)
{
if (subjectKeyId.SubjectKeyIdentifier != authorityKeyId)
{
return false;
}
}
}
// found match.
return true;
}