title: No error encrypting / decrypting data with an expired certificate using RSACryptoServiceProvider
body: <p>I currently doing a proof of concept to encrypt data using a certificate. It works well but now, I want to try a scenario when the certificate is expired. I created an expired certificate and I was surprise to notice that everthing works property even with the expired certificate. I was expecting an error.</p>
  
  <p>Do you know if it's because it's a self signed certificate ?</p>
  
  <p>Here's the code I using to test my case</p>
  
  <pre><code>[TestMethod]
  public void Encrypt_decrypt_with_expired_certificate()
  {
      //Arrange
      var baseString = "This is an encryption test";
      X509Certificate2 newX509Certificate2 = new X509Certificate2("d:\\testx509certExpired.pfx", "apassword");
      Console.WriteLine(newX509Certificate2.NotAfter); //Show the expiration date which is in the past
      var encryptor = new CertificateEncryptor(newX509Certificate2); //This class is a simple wrapper around RSACryptoServiceProvider
  
      //Act
      string encryptedResult = encryptor.Encrypt(baseString); //Exception expected because of the expired certificate but not thrown
  
      //Assert
      Console.WriteLine("Base string : {0}", baseString);
      Console.WriteLine("Encrypted string : {0}", encryptedResult);
      Assert.IsNotNull(encryptedResult);
  
      //revert back
      string decryptedString = encryptor.Decrypt(encryptedResult);
      Console.WriteLine("Decrypted string : {0}", decryptedString);
      Assert.AreEqual(baseString, decryptedString);
  }
  </code></pre>
  
  <p>Thanks</p>