C#,coding with AES

Posted by lolalola on Stack Overflow See other posts from Stack Overflow or by lolalola
Published on 2010-04-18T20:41:08Z Indexed on 2010/04/18 20:43 UTC
Read the original article Hit count: 415

Filed under:
|

Hi, why i can coding only 128 bytes text?

Work: string plainText = "1234567890123456"; Don't work: string plainText = "12345678901234561"; Don't work: string plainText = "123456789012345";

            string plainText = "1234567890123456";
        byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);

        byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes("1234567890123456");

        byte[] initVectorBytes = System.Text.Encoding.UTF8.GetBytes("1234567890123456");

        RijndaelManaged symmetricKey = new RijndaelManaged();
        symmetricKey.Mode = CipherMode.CBC;
        symmetricKey.Padding = PaddingMode.Zeros;

        ICryptoTransform encryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes);

        MemoryStream memoryStream = new MemoryStream();

        CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write);

        cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);

        cryptoStream.FlushFinalBlock();

        byte[] cipherTextBytes = memoryStream.ToArray();

        memoryStream.Close();
        cryptoStream.Close();

        string cipherText = Convert.ToBase64String(cipherTextBytes);

        Console.ReadLine();

© Stack Overflow or respective owner

Related posts about c#

Related posts about aes