Пример #1
0
        private X509Certificate2 LoadCertificate()
        {
            var certificates = _certificatesGenerator.LoadCertificate();

            X509Certificate2 certificate = null;

            foreach (var cert in certificates)
            {
                if (certificate == null || certificate.NotAfter <= DateTime.Now.AddDays(2))
                {
                    certificate = cert;
                }
            }

            if (certificate == null)
            {
                certificate = _certificatesGenerator.GenerateCertificate();
                _certificatesGenerator.SaveCertificate(certificate);
            }

            return(certificate);
        }
        private void CheckCertificates()
        {
            var certificates = _certificatesGenerator.LoadCertificate();

            X509Certificate2 certificate = null;

            foreach (var cert in certificates)
            {
                if (certificate == null || certificate.NotAfter <= DateTime.Now.AddDays(2))
                {
                    certificate = cert;
                }
            }

            if (certificate != null && certificate.NotAfter > DateTime.Now.AddDays(2))
            {
                return;
            }

            certificate = _certificatesGenerator.GenerateCertificate();
            _certificatesGenerator.SaveCertificate(certificate);
        }