/// <summary> /// Checks whether specified private key matches this certificate /// </summary> /// <param name="privateKey">Private key to be checked</param> /// <returns>Null if match cannot be performed, true if private key matches, false otherwise</returns> public bool? Matches(PrivateKey privateKey) { if (privateKey == null || privateKey.PublicKey == null) return null; if (this.PublicKey == null) return null; return this.PublicKey.Equals(privateKey.PublicKey); }
/// <summary> /// Identifies certificates matching specified private key /// </summary> /// <param name="privateKey">Private key</param> /// <param name="certificates">Certificates that should be analyzed</param> /// <returns>Indexes of matching certificates</returns> static int[] GetMatchingCertIds(PrivateKey privateKey, List<Certificate> certificates) { List<int> indexes = new List<int>(); int i = 1; foreach (Certificate certificate in certificates) { bool? matches = privateKey.Matches(certificate); if (matches.HasValue && matches.Value == true) indexes.Add(i); i++; } return indexes.ToArray(); }