LoadPrivateKey() public method

Loads the private key from a PFX file in the certificate store.
public LoadPrivateKey ( string thumbprint, string subjectName, string password ) : X509Certificate2
thumbprint string
subjectName string
password string
return System.Security.Cryptography.X509Certificates.X509Certificate2
        /// <summary>
        /// Loads the private key for the certificate with an optional password.
        /// </summary>
        public async Task <X509Certificate2> LoadPrivateKey(String password)
        {
            if (this.StoreType == CertificateStoreType.Directory)
            {
                using (DirectoryCertificateStore store = new DirectoryCertificateStore())
                {
                    store.Open(this.StorePath);
                    m_certificate = store.LoadPrivateKey(this.Thumbprint, this.SubjectName, password);
                    return(m_certificate);
                }
            }

            return(await Find(true));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the private key for the certificate with an optional password.
        /// </summary>
        public X509Certificate2 LoadPrivateKey(System.Security.SecureString password)
        {
            #if !SILVERLIGHT
            if (this.StoreType == CertificateStoreType.Directory)
            {
                DirectoryCertificateStore store = new DirectoryCertificateStore();
                store.Open(this.StorePath);
                m_certificate = store.LoadPrivateKey(this.Thumbprint, this.SubjectName, password);
                return(m_certificate);
            }
            #endif

            return(Find(true));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the private key for the certificate with an optional password.
        /// </summary>
        public Task <X509Certificate2> LoadPrivateKeyEx(ICertificatePasswordProvider passwordProvider)
        {
            if (this.StoreType == CertificateStoreType.Directory)
            {
                using (DirectoryCertificateStore store = new DirectoryCertificateStore())
                {
                    store.Open(this.StorePath);
                    string password = passwordProvider?.GetPassword(this);
                    m_certificate = store.LoadPrivateKey(this.Thumbprint, this.SubjectName, password);
                    return(Task.FromResult(m_certificate));
                }
            }

            return(Find(true));
        }
 /// <summary>
 /// Loads the private key for the certificate with an optional password.
 /// </summary>
 public async Task<X509Certificate2> LoadPrivateKey(String password)
 {
     if (this.StoreType == CertificateStoreType.Directory)
     {                
         using (DirectoryCertificateStore store = new DirectoryCertificateStore())
         {
             store.Open(this.StorePath);
             m_certificate = store.LoadPrivateKey(this.Thumbprint, this.SubjectName, password);
             return m_certificate;
         }
     }
     
     return await Find(true);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Loads the private key for the certificate with an optional password.
        /// </summary>
        public X509Certificate2 LoadPrivateKey(System.Security.SecureString password)
        {
            #if !SILVERLIGHT
            if (this.StoreType == CertificateStoreType.Directory)
            {                
                using (DirectoryCertificateStore store = new DirectoryCertificateStore())
                {
                    store.Open(this.StorePath);
                    m_certificate = store.LoadPrivateKey(this.Thumbprint, this.SubjectName, password);
                    return m_certificate;
                }
            }
            #endif

            return Find(true);
        }