Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 478491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:41:49+00:00 2026-05-13T00:41:49+00:00

OK, so having just got the key to be accepted and have an encrypted

  • 0

OK, so having just got the key to be accepted and have an encrypted string out which is 44 char long, I now am unable to decrypt (aarrgghh):

Length of the data to decrypt is invalid.

Having looked around and read various posts it looks as though the conversion to a Base64String may be the problem but I can’t see where it is wrong – many of the solutions I have seen appear to be identical to what I have. Again, I’d really appreciate any help – extracts below:

Encryption/Decryption Function

Private byteKey As Byte() = Encoding.UTF8.GetBytes("B499F4BF48242E05548D1E4C8BB26A2E")
Private byteIV As Byte() = Encoding.UTF8.GetBytes(",%u'm&'CXSy/T7x;4")

Private Function Rijndael(ByVal sInput As String, ByVal bEncrypt As Boolean) As String
    ' Create an instance of encyrption algorithm. 
    Dim _rijndael As New RijndaelManaged()
    ' Create an encryptor using key and IV - already available in byte() as byteKey and byteIV
    Dim transform As ICryptoTransform
    If bEncrypt Then
        transform = _rijndael.CreateEncryptor(byteKey, byteIV)
    Else
        transform = _rijndael.CreateDecryptor(byteKey, byteIV)
    End If
    ' Create streams for input and output 
    Dim msOutput As New System.IO.MemoryStream()
    Dim msInput As New CryptoStream(msOutput, transform, CryptoStreamMode.Write)
    ' Feed data into the crypto stream. 
    msInput.Write(Encoding.UTF8.GetBytes(sInput), 0, Encoding.UTF8.GetBytes(sInput).Length)
    ' Flush crypto stream. 
    msInput.FlushFinalBlock()
    Dim byteOutput As Byte() = msOutput.ToArray
    Return Convert.ToBase64String(byteOutput)
End Function

Usage:

Dim sEncrypted As String = Rijndael("This is a test", True)
Dim sDecrypted As String = Rijndael(sEncrypted, False) **This is the line where it is crashing**

EDIT – Final, seemingly working pair of functions (see comment) for ref:

Private byteKey As Byte() = Encoding.UTF8.GetBytes("B499F4BF48242E05548D1E4C8BB26A2E")
Private byteIV As Byte() = Encoding.UTF8.GetBytes(",%u'm&'CXSy/T7x;4")

Public Function Encrypt(ByVal sInput As String) As String
    ' Create an instance of our encyrption algorithm. 
    Dim _rijndael As New RijndaelManaged()
    ' Create an encryptor using our key and IV 
    Dim transform As ICryptoTransform
    transform = _rijndael.CreateEncryptor(byteKey, byteIV)
    ' Create the streams for input and output 
    Dim msOutput As New System.IO.MemoryStream()
    Dim msInput As New CryptoStream(msOutput, transform, CryptoStreamMode.Write)
    ' Feed our data into the crypto stream 
    msInput.Write(Encoding.UTF8.GetBytes(sInput), 0, Encoding.UTF8.GetBytes(sInput).Length)
    msInput.FlushFinalBlock()
    Return Convert.ToBase64String(msOutput.ToArray)
End Function

Public Function Decrypt(ByVal sInput As String) As String
    ' Create an instance of our encyrption algorithm. 
    Dim _rijndael As New RijndaelManaged()
    ' Create an encryptor using our key and IV 
    Dim transform As ICryptoTransform
    transform = _rijndael.CreateDecryptor(byteKey, byteIV)
    ' Create the streams for input and output 
    Dim msOutput As New System.IO.MemoryStream()
    Dim msInput As New CryptoStream(msOutput, transform, CryptoStreamMode.Write)
    ' Feed our data into the crypto stream. 
    msInput.Write(Convert.FromBase64String(sInput), 0, Convert.FromBase64String(sInput).Length)
    msInput.FlushFinalBlock()
    Return Encoding.UTF8.GetString(msOutput.ToArray)
End Function

Usage

Dim sEncrypted As String = Encrypt("This is a test")
Dim sDecrypted As String = Decrypt(sEncrypted) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:41:50+00:00Added an answer on May 13, 2026 at 12:41 am

    If you’re going to convert it to base64 you’re going to have to decode it using Base64. At the moment you’re taking the output Base64 byte array then using UTF8 to convert it back to bytes, which gives you a completely different value.

    You should be using Convert.FromBase64String instead of UTF8 for changing the string to bytes when decoding, then using UTF8 instead of Base64 for interpreting the data.

    EG: On the decode you’d want

    msInput.Write(Convert.FromBase64String(sInput), 0, Convert.FromBase64String(sInput).Length)
    

    And for the return when decoding:

    Return Encoding.UTF8.GetString(byteOutput)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below which I got from the php: mktime manual just
Right now I'm building a personal site/blog and have pretty much got it they
Having just read the first four chapters of Refactoring: Improving the Design of Existing
I'm completely new to Flex and am just having a play with a sample
I've just introduced a friend to GNU Screen and they're having a hard time
Someone at work just asked for the reasoning behind having to wrap a wait
I'm having an issue with CruiseControl.net where the web dashboard just won't work in
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
I'm having problems redirecting stdio of another program using subprocess module. Just reading from
How would you test this scenario? I've just started looking into NHibernate and having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.