How do I remove .net CryptoStream padding
<p>When I use the following class the output is padded. </p>

<pre><code>public static string EncryptString(string ClearText) {
  byte[] clearTextBytes = Encoding.UTF8.GetBytes(ClearText);
  System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
  MemoryStream ms = new MemoryStream();
  byte[] rgbIV = Encoding.ASCII.GetBytes("ryojvlzmdalyglrj");
  byte[] key = Encoding.ASCII.GetBytes("hcxilkqbbhczfeultgbskdmaunivmfuo");            
  CryptoStream cs = new CryptoStream(ms, rijn.CreateEncryptor(key, rgbIV),
           CryptoStreamMode.Write);
  cs.Write(clearTextBytes, 0, clearTextBytes.Length);
  cs.Close();
  return Convert.ToBase64String(ms.ToArray());
}

public static string DecryptString(string EncryptedText)
        {
  byte[] encryptedTextBytes = Convert.FromBase64String(EncryptedText);

  MemoryStream ms = new MemoryStream();

  System.Security.Cryptography.SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
  rijn.Mode = CipherMode.CFB;

  byte[] rgbIV = Encoding.ASCII.GetBytes("ryojvlzmdalyglrj");
  byte[] key = Encoding.ASCII.GetBytes("hcxilkqbbhczfeultgbskdmaunivmfuo"); ;

  CryptoStream cs = new CryptoStream(ms, rijn.CreateDecryptor(key, rgbIV),
  CryptoStreamMode.Write);

  cs.Write(encryptedTextBytes, 0, encryptedTextBytes.Length);

  cs.Close();

  return Encoding.UTF8.GetString(ms.ToArray());
}
</code></pre>

<p>I understood from another post that there is </p>

<pre><code>rijn.Padding = PaddingMode.None;
</code></pre>

<p>When I added this I get an error that says "Length of the data to encrypt is invalid"</p>

<p>Even when I try to encrypt a 6 byte string then I see get a long result. </p>

<pre><code>var def1 = Encrypt.EncryptString("abcdefg");
</code></pre>

<p>gives me 24 bytes!</p>

<p>Can someone give me some advice here.</p>

<p>UPDATE</p>

<p>Changed to the following:</p>

<pre><code>        byte[] bytOut = ms.GetBuffer();
        int i = 0;
        for (i = 0; i &lt; bytOut.Length; i++)
            if (bytOut[i] == 0)
                break;

        // convert into Base64 so that the result can be used in xml

        return System.Convert.ToBase64String(bytOut, 0, i);
</code></pre>

<p>When I check bytOut it's 16bytes Then the value returned after ToBase64 is 24 bytes. I am still not sure why the size is so large</p>
