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