Get Certificate - CSharp System.Security.Cryptography

CSharp examples for System.Security.Cryptography:Certificate

Description

Get Certificate

Demo Code


using System.Threading;
using System.Diagnostics;
using System.Security.Cryptography.X509Certificates;
using System;//ww w.jav a2s.c o  m

public class Main{
        public static X509Certificate2 GetCertificate(string RootCertificateName, string Hostname)
        {

            if (store == null)
            {
                store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
                store.Open(OpenFlags.ReadOnly);
            }
            var CachedCertificate = GetCertifiateFromStore(RootCertificateName, Hostname);

            if (CachedCertificate == null)
                CreateClientCertificate(RootCertificateName, Hostname);

            return GetCertifiateFromStore(RootCertificateName, Hostname);


        }
}

Related Tutorials