title: AesManaged started to produce null string encryption result after years of working perfectly
body: <p>A few years ago I wrote a simple wrapper based on <a href="https://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged.aspx" rel="nofollow">MSDN - AesManaged Class</a> code, to obscure values saved in registry (simply to prevent manual tampering with these, nothing more):</p>
  
  <pre><code>public static string    Encrypt( string s, byte[] key, byte[] iv )
  {
      byte[]  enc;
  
      using(  AesManaged aes =    new AesManaged( )  )
      {
          ICryptoTransform    ict =   aes.CreateEncryptor( key, iv );
  
          using(  MemoryStream ms= new MemoryStream( )  )
          using(  CryptoStream cs= new CryptoStream( ms, ict, CryptoStreamMode.Write )  )
          using(  StreamWriter sw= new StreamWriter( cs )  )
          {
              sw.Write( s );      enc =   ms.ToArray( );
          }
      }
      return  Convert.ToBase64String( enc );
  }
  
  public static string    Decrypt( string p, byte[] key, byte[] iv )
  {
      string  s=  null;
  
      using(  AesManaged aes =    new AesManaged( )  )
      {
          ICryptoTransform    ict =   aes.CreateDecryptor( key, iv );
  
          using(  MemoryStream ms= new MemoryStream( Convert.FromBase64String( p ) )  )
          using(  CryptoStream cs= new CryptoStream( ms, ict, CryptoStreamMode.Read )  )
          using(  StreamReader sr= new StreamReader( cs )  )
          {
              s=  sr.ReadToEnd( );
          }
      }
      return  s;
  }
  </code></pre>
  
  <p>These methods worked perfectly all this time .. until yesterday, when Encrypt produced a null result on a valid string.  Changing <code>key</code> and <code>iv</code> does not make any difference.  Tried executing on several machines - same result.  No exceptions are thrown.  However, decryption still works fine!</p>
  
  <p>Why does <code>Encrypt( )</code> suddenly fail?  Is there some Windows Update that changed the play-field?</p>