Results 1 to 2 of 2

Thread: [RESOLVED] Padding error...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Resolved [RESOLVED] Padding error...

    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.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Padding error...

    I got the answer, I had been passing the wrong variables. Thread solved!
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width