Internal.Cryptography.Pal.DirectoryBasedStoreProvider.FindExistingFilename C# (CSharp) Method

FindExistingFilename() private static method

private static FindExistingFilename ( X509Certificate2 cert, string storePath, bool &hadCandidates ) : string
cert System.Security.Cryptography.X509Certificates.X509Certificate2
storePath string
hadCandidates bool
return string
        private static string FindExistingFilename(X509Certificate2 cert, string storePath, out bool hadCandidates)
        {
            hadCandidates = false;

            foreach (string maybeMatch in Directory.EnumerateFiles(storePath, cert.Thumbprint + PfxWildcard))
            {
                hadCandidates = true;

                try
                {
                    using (X509Certificate2 candidate = new X509Certificate2(maybeMatch))
                    {
                        if (candidate.Equals(cert))
                        {
                            return maybeMatch;
                        }
                    }
                }
                catch (CryptographicException)
                {
                    // Contents weren't interpretable as a certificate, so it's not a match.
                }
            }

            return null;
        }