Hello, this is my code:

vb.net Code:
  1. Public Overloads Shared Function RijndaelDecryptString(ByVal text As String, ByVal key As String) As String
  2.         Dim _encKey As Byte() = CheckKey(key)
  3.         Dim _textBytes As Byte() = Convert.FromBase64String(text)
  4.         Return RijndaelDecryptString(_encKey, _textBytes)
  5.     End Function
  6.  
  7.     Public Overloads Shared Function RijndaelDecryptString(ByVal data As Byte(), ByVal key As Byte())
  8.         Try
  9.             _rijndaelAlg.BlockSize = 256
  10.             Dim _memStream As New MemoryStream(data)
  11.             Dim _decryptedText(data.Length - 1) As Byte
  12.             Dim cStream As New CryptoStream(_memStream, _
  13.                                             _rijndaelAlg.CreateDecryptor(key, _IV), _
  14.                                             CryptoStreamMode.Read)
  15.             cStream.Read(_decryptedText, 0, _decryptedText.Length)
  16.             cStream.Close()
  17.             _memStream.Close()
  18.             Return _encoding.GetString(_decryptedText)
  19.         Catch ex As Exception
  20.             Return ex.Message
  21.         End Try
  22.     End Function

Now, when I run that code it gives me the following error:

Padding is invalid and cannot be removed.

But, if I put everything into one function it works like a charm, why is that?

Thanks in advance!

P.S: I'm creating a class, that's why I'm using Overloads.