InMemoryCertificate GetOrUpdateCertificate(InMemoryCertificate cert, ICertificateProvider certificateProvider)
 {
     lock (sync)
     {
         if (cert == null)
         {
             cert = new InMemoryCertificate(certificateProvider.GetCertificate(), inMemLifeSpan, timeProvider);
         }
         if (cert.IsExpired)
         {
             cert.UpdateUsing(certificateProvider);
         }
         return(cert);
     }
 }
 public X509Certificate2 ClientEncryptionCertificate()
 {
     clientEncryptionCertificate = GetOrUpdateCertificate(clientEncryptionCertificate, clientEncryptionCertificateProvider);
     return(clientEncryptionCertificate.X509);
 }