示例#1
0
        /// <summary>
        /// Loads the private key for the certificate with an optional password.
        /// </summary>
        public async Task <X509Certificate2> LoadPrivateKeyEx(ICertificatePasswordProvider passwordProvider)
        {
            if (this.StoreType != CertificateStoreType.X509Store)
            {
                using (ICertificateStore store = CertificateStoreIdentifier.CreateStore(StoreType))
                {
                    if (store.SupportsLoadPrivateKey)
                    {
                        store.Open(this.StorePath, false);
                        string password = passwordProvider?.GetPassword(this);
                        m_certificate = await store.LoadPrivateKey(this.Thumbprint, this.SubjectName, password).ConfigureAwait(false);

                        return(m_certificate);
                    }
                }
            }
            return(await Find(true).ConfigureAwait(false));
        }