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 8632889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:24:48+00:00 2026-06-12T09:24:48+00:00

I have this bit of C# code that I have translated to VB using

  • 0

I have this bit of C# code that I have translated to VB using http://www.developerfusion.com/tools/convert/csharp-to-vb/

private string DecodeToken (string token, string key)
{           
    byte [] buffer = new byte[0];
    string decoded = "";
    int i;
        if (Scramble (Convert.FromBase64String(token), key, ref buffer))
    {
        for (i=0;i<buffer.Length;i++)
        {
            decoded += Convert.ToString((char)buffer[i]);
        }
    }
    return(decoded);
}

Which, after a little modification, gives this:

Private Function DecodeToken(token As String, key As String) As String
    Dim buffer As Byte()
    Dim decoded As String = ""
    Dim index As Integer
    If Scramble(Convert.FromBase64String(token), key, buffer) Then
        For index = 0 To buffer.Length - 1
            decoded += Convert.ToString(ChrW(buffer(index)))
        Next
        'decoded = UTF8Encoding.ASCII.GetString(pbyBuffer)
        'decoded = UnicodeEncoding.ASCII.GetString(pbyBuffer)
        'decoded = ASCIIEncoding.ASCII.GetString(pbyBuffer)
    End If
    Return decoded
End Function

Scramble just rearranges the array in a specific way and I’ve checked the VB and C# outputs against each other so it can be ignored. It’s inputs and outputs are byte arrays so it shouldn’t affect the encoding.

The problem lies in that the result of this function is fed into a hashing algorithm which is then compared against the hashing signature. The result of the VB version, when hashed, does not match to the signature.

You can see from the comments that I’ve attempted to use different encodings to get the byte buffer out as a string but none of these have worked.

The problem appears to lie in the transalation of decoded += Convert.ToString((char)buffer[i]); to decoded += Convert.ToString(ChrW(buffer(index))).

Does ChrW produce the same result as casting as a char and which encoding will correctly duplicate the reading of the byte array?

Edit: I always have Option Strict On but it’s possible that the original C# doesn’t so it may be affected by implicit conversion. What does the compiler do in that situation?

  • 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-06-12T09:24:48+00:00Added an answer on June 12, 2026 at 9:24 am

    Quick answer

    decoded += Convert.ToString((char)buffer[i]);
    

    is equivalent to

    decoded &= Convert.ToString(Chr(buffer[i]));
    

    VB.Net stops you taking the hacky approach used in the c# code, a Char is Unicode so consists of two bytes.


    This looks likes a better implementation of what you have.

    Private Function DecodeToken(encodedToken As String, key As String) As String
        Dim scrambled = Convert.FromBase64String(encodedToken)
        Dim buffer As Byte()
        Dim index As Integer
    
        If Not Scramble(scrambled, key, buffer) Then
            Return Nothing
        End If
    
        Dim descrambled = new StringBuilder(buffer.Length);
    
        For index = 0 To buffer.Length - 1
            descrambled.Append(Chr(buffer(index)))
        Next
    
        Return descrambled.ToString()
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this bit of code that helps me convert enum to string and
I have a bit of sample code that is throwing this warning: main.c: In
I have this bit of code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
I have this bit of code that is being converted from vb6 to vb.net.
I have this bit of code that is receiving a series of messages: byte[]
Well, I have this bit of code that is slowing down the program hugely
I have this little bit of code that I can't quite work correctly. The
i have this bit of code, it limits the Li's to 15 of them
I have this bit of code, public static List<string> GetSentencesFromWords(List<string> words, string fileContents) {
So I have this bit of code for x in range(x1,x2): for y in

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.