Note that there are some explanatory texts on larger screens.

plurals
  1. PORijndael encryption/decryption
    text
    copied!<p>I have the following code for encryption and decryption. The problem is that at decryption besides the decrypted text i have some "aaaaa" after the text. why? need some help. THX!</p> <pre><code>public static byte[] Encrypt(byte[] PlainTextBytes, string key , string InitialVector) { try { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); Byte[] KeyBytes = encoding.GetBytes(key); byte[] InitialVectorBytes = encoding.GetBytes(InitialVector); RijndaelManaged SymmetricKey = new RijndaelManaged(); ICryptoTransform Encryptor = SymmetricKey.CreateEncryptor(KeyBytes, InitialVectorBytes); MemoryStream MemStream = new MemoryStream(); CryptoStream CryptoStream = new CryptoStream(MemStream, Encryptor, CryptoStreamMode.Write); CryptoStream.Write(PlainTextBytes, 0, PlainTextBytes.Length); CryptoStream.FlushFinalBlock(); byte[] CipherTextBytes = MemStream.ToArray(); return CipherTextBytes; </code></pre> <p>//decrytion</p> <pre><code>public static string Decrypt(byte[] PlainTextBytes1, string key, string InitialVector) { System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); Byte[] KeyBytes = encoding.GetBytes(key); RijndaelManaged SymmetricKey = new RijndaelManaged(); byte[] InitialVectorBytes = Encoding.UTF8.GetBytes(InitialVector); ICryptoTransform Decryptor = SymmetricKey.CreateDecryptor(KeyBytes, InitialVectorBytes); MemoryStream MemStream1 = new MemoryStream(PlainTextBytes1); CryptoStream CryptoStream = new CryptoStream(MemStream1, Decryptor, CryptoStreamMode.Read); Byte[] pltxt = new byte[PlainTextBytes1.Length]; CryptoStream.Read(pltxt, 0, pltxt.Length); ASCIIEncoding textConverter = new ASCIIEncoding(); round = textConverter.GetString(pltxt); return round; } </code></pre> <p>where am i wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload