377

I am trying to "decode" this following Base64 string:

OBFZDTcPCxlCKhdXCQ0kMQhKPh9uIgYIAQxALBtZAwUeOzcdcUEeW0dMO1kbPElWCV1ISFFKZ0kdWFlLAURPZhEFQVseXVtPOUUICVhMAzcfZ14AVEdIVVgfAUIBWVpOUlAeaUVMXFlKIy9rGUN0VF08Oz1POxFfTCcVFw1LMQNbBQYWAQ==

This is what I know about the string itself:

  1. The original string is first passed through the following code:

    private static string m000493(string p0, string p1)
    {
        StringBuilder builder = new StringBuilder(p0);
        StringBuilder builder2 = new StringBuilder(p1);
        StringBuilder builder3 = new StringBuilder(p0.Length);
        int num = 0;
    Label_0084:
        while (num < builder.Length)
        {
            int num2 = 0;
            while (num2 < p1.Length)
            {
                if ((num == builder.Length) || (num2 == builder2.Length))
                {
                    MessageBox.Show("EH?");
                    goto Label_0084;
                }
                char ch = builder[num];
                char ch2 = builder2[num2];
                ch = (char)(ch ^ ch2);
                builder3.Append(ch);
                num2++;
                num++;
            }
        }
        return m0001cd(builder3.ToString());
    }
    

    The p1 part in the code is supposed to be the string "_p0lizei.".

  2. It is then converted to a Base64 string by the following code:

    private static string m0001cd(string p0)
    {
        string str2;
        try
        {
            byte[] buffer = new byte[p0.Length];
            str2 = Convert.ToBase64String(Encoding.UTF8.GetBytes(p0));
        }
        catch (Exception exception)
        {
            throw new Exception("Error in base64Encode" + exception.Message);
        }
        return str2;
    }
    

The question is, how do I decode the Base64 string so that I can find out what the original string is?

2
  • 3
    I know "Why" is generally irrelevant when supporting legacy stuff, but I need to know... Why was the original string Base64 encoded in the first place?!?? Base64 is usually used to convert binary into a text based portable version for embedding in XML or JSON - possibly to move across a web service layer, not for converting string into encoded string. Commented Aug 1, 2014 at 17:36
  • 1
    @barry - to answer your old question on an even older post... I got here because I need to deal with HTTP Authorization Header which requires base64 encoded string Commented Apr 1, 2020 at 9:27

3 Answers 3

957
byte[] data = Convert.FromBase64String(encodedString);
string decodedString = System.Text.Encoding.UTF8.GetString(data);
Sign up to request clarification or add additional context in comments.

2 Comments

To complete this answer, Jerry Nixon has a great post on this.
and dont forget to add namespace 'using System.Text'
113

The m000493 method seems to perform some kind of XOR encryption. This means that the same method can be used for both encoding and decoding the text. All you have to do is reverse m0001cd:

string p0 = Encoding.UTF8.GetString(Convert.FromBase64String("OBFZDT..."));

string result = m000493(p0, "_p0lizei.");
//    result == "gaia^unplugged^Ta..."

with return m0001cd(builder3.ToString()); changed to return builder3.ToString();.

2 Comments

@Rickard: You can "accept" an answer that solves your problem by clicking the checkmark next to the answer on the left side.
Please do not refer to any of this as "encryption" or "decryption". Make it a point to distinguish between "encryption" and "encoding".
10
    // Decode a Base64 string to a string
    public static string DecodeBase64(string value)
    {
        if(string.IsNullOrEmpty(value))
            return string.Empty;
        var valueBytes = System.Convert.FromBase64String(value);
        return System.Text.Encoding.UTF8.GetString(valueBytes);
    }

1 Comment

This answer seems to use same method as others...

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.