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

  • SEARCH
  • Home
  • 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'm using XSLT and having great success, just got a couple of problems. Warning:
Question says it all. I'm just having trouble figuring this out. What i'm trying
I just recently got into using vim, and am having great fun adding load
Right now I'm building a personal site/blog and have pretty much got it they
Having just added a new button in my web application, I get an error
Having just pulled my hair off because of a difference, I'd like to know
Having just updated Mono to 2.6.3 (on OS X), I noticed in the installer
Having just started with MVC 2 I notice that in their starter template they
... after having just read http://www.cocoadev.com/index.pl?CocoaInsecurity ... I am curious to know about your
I'm just having an issue I'm hoping someone will be able to give me

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.