title: Encrypt Decrypt in C# Decrypt is not working
body: <p>I had a java code and I had to transform it in C# which is as below</p>
  
  <p>Encryption:</p>
  
  <pre><code> public String encrypt(String value)
      {
          System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
          AesManaged tdes = new AesManaged();
          tdes.Key = UTF8.GetBytes(securityKey);
          tdes.Mode = CipherMode.ECB;
          tdes.Padding = PaddingMode.PKCS7;
          ICryptoTransform crypt = tdes.CreateEncryptor();
          byte[] plain = Encoding.UTF8.GetBytes(value);
          byte[] cipher = crypt.TransformFinalBlock(plain, 0, plain.Length);
          String encryptedText = Convert.ToBase64String(cipher);
          return encryptedText;
      }
  </code></pre>
  
  <p>Now I am trying to write the reversal process</p>
  
  <pre><code>public String decrypt(String value)
      {                   
          System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
          AesManaged tdes = new AesManaged();
          tdes.Key = UTF8.GetBytes(securityKey);
          tdes.Mode = CipherMode.ECB;
          tdes.Padding = PaddingMode.PKCS7;
          ICryptoTransform crypt = tdes.CreateDecryptor();
          byte[] plain = Encoding.UTF8.GetBytes(value);
          byte[] cipher = crypt.TransformFinalBlock(plain, 0, plain.Length);
          String encryptedText = Convert.ToBase64String(cipher);
          return encryptedText;
      }
  </code></pre>
  
  <p>But the reversal is not working.<br/></p>
  
  <p>Error:  An exception of type</p>
  
  <blockquote>
    <p>'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll but was not handled in user code</p>
    
    <p>Additional information: Padding is invalid and cannot be removed.</p>
  </blockquote>
  
  <p>Stack Trace:</p>
  
  <blockquote>
    <p>System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]&amp; outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
       at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
       at redis2.Crypto.AESECBPKCS5PaddingEncryptor.decrypt(String value) in e:\TestApplication\Redis\redis2\redis2\Crypto\AESECBPKCS5PaddingEncryptor.cs:line 53
       at redis2.WebForm1.Page_Load(Object sender, EventArgs e) in e:\TestApplication\Redis\redis2\redis2\WebForm1.aspx.cs:line 14
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)</p>
  </blockquote>
  
  <h2>update 1</h2>
  
  <pre><code> public String decrypt(String value)
      {                   
          System.Text.UTF8Encoding UTF8 = new System.Text.UTF8Encoding();
          AesManaged tdes = new AesManaged();
          tdes.Key = UTF8.GetBytes(securityKey);
          tdes.Mode = CipherMode.ECB;
          tdes.Padding = PaddingMode.PKCS7;
          ICryptoTransform crypt = tdes.CreateDecryptor();
         // value = Convert.FromBase64String(value);
          byte[] plain = Convert.FromBase64String(value);
          byte[] cipher = crypt.TransformFinalBlock(plain, 0, plain.Length);
          String encryptedText = Convert.ToBase64String(cipher);
          return encryptedText;
      }
  </code></pre>