Hello, this is my code:
vb.net Code:
Public Overloads Shared Function RijndaelDecryptString(ByVal text As String, ByVal key As String) As String Dim _encKey As Byte() = CheckKey(key) Dim _textBytes As Byte() = Convert.FromBase64String(text) Return RijndaelDecryptString(_encKey, _textBytes) End Function Public Overloads Shared Function RijndaelDecryptString(ByVal data As Byte(), ByVal key As Byte()) Try _rijndaelAlg.BlockSize = 256 Dim _memStream As New MemoryStream(data) Dim _decryptedText(data.Length - 1) As Byte Dim cStream As New CryptoStream(_memStream, _ _rijndaelAlg.CreateDecryptor(key, _IV), _ CryptoStreamMode.Read) cStream.Read(_decryptedText, 0, _decryptedText.Length) cStream.Close() _memStream.Close() Return _encoding.GetString(_decryptedText) Catch ex As Exception Return ex.Message End Try 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.





Reply With Quote