ошибка ввода данных не завершена блок - PullRequest
0 голосов
/ 09 марта 2019

enter image description here

Я создаю приложение чата и использую алгоритм AES.Но я вижу эту ошибку «входные данные не полный блок».

Это мой код:

        public static string DecryptStringFromBytes_Aes(byte[] cipherText, string key, string mode)
    {
        // Check arguments.
        if (cipherText == null || cipherText.Length <= 0)
            throw new ArgumentNullException("cipherText");

        // Declare the string used to hold
        // the decrypted text.
        string plaintext = null;

        // Create an Aes object
        // with the specified key and IV.
        using (Aes aesAlg = Aes.Create())
        {
            if (mode == "ECB") aesAlg.Mode = CipherMode.ECB;
            else if (mode == "CBC") aesAlg.Mode = CipherMode.CBC;
            else if (mode == "CFB") aesAlg.Mode = CipherMode.CFB;

            aesAlg.Key = Convert.FromBase64String(key);
            aesAlg.IV = ASCIIEncoding.ASCII.GetBytes(key.Substring(0, 16));

            // Create a decryptor to perform the stream transform.
            ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV);

            // Create the streams used for decryption.
            using (MemoryStream msDecrypt = new MemoryStream(cipherText))
            {
                using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
                {
                    using (StreamReader srDecrypt = new StreamReader(csDecrypt))
                    {

                        // Read the decrypted bytes from the decrypting stream
                        // and place them in a string.
                        plaintext = srDecrypt.ReadToEnd();
                    }
                }
            }
        }
        return plaintext;
    }

Ошибка в строке: plaintext = srDecrypt.ReadToEnd ();Я не знаю почему.

Помогите мне, пожалуйста.Большое спасибо.

...