AES in CBC mode is a block cipher, that is the input and output is in block sized chunks.
If the input to encryption might not always be a multiple of the block size padding can be added (PKCS#7 padding in the question code) to the data to be encrypted to make it so. The output will be a multiple of the block size.
Because of this the question does not make sense, the encrypted data will always be a multiole of the block size if PKCS#7 padding is used (as in the code).
On decryption the decrypted output will be a multiple of the block size and then the padding can be removed.
By specifying PKCS#7 padding int he APIU call the padding/de-padding will happen in the API.
There are other modes such as CTR where the output is the same length as the input, they are in general "streaming" modes and have their own complications such as never using the same nonce with the same key.
hi Here is the code after the modifications and it works fine.
The changes I made to the previous code is converting the cipher text from Base64 string to the bytes format and at last while returning the String convert it to the System.Text.Encoding.UTF8.GetString format.
public static string DecryptStringAES(string cipherText)
if (cipherText == null || cipherText.Length <= 0)
throw new ArgumentNullException("plainText");
String key = "0102030405060708";
String iv = "1020304050607080";
if (key == null || key.Length <= 0)
throw new ArgumentNullException("Key");
if (iv == null || iv.Length <= 0)
throw new ArgumentNullException("IV");
byte bytearraytodecrypt = Convert.FromBase64String(cipherText);