[c#] How do I decode a base64 encoded string?

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?

This question is related to c# encoding base64

The answer is


The m000493 method seems to perform some kind of XOR encryption. This means that the same method can be used for both encrypting and decrypting 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();.


Simple:

byte[] data = Convert.FromBase64String(encodedString);
string decodedString = Encoding.UTF8.GetString(data);

Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to encoding

How to check encoding of a CSV file UnicodeEncodeError: 'ascii' codec can't encode character at special name Using Javascript's atob to decode base64 doesn't properly decode utf-8 strings What is the difference between utf8mb4 and utf8 charsets in MySQL? The character encoding of the plain text document was not declared - mootool script UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 23: ordinal not in range(128) How to encode text to base64 in python UTF-8 output from PowerShell Set Encoding of File to UTF8 With BOM in Sublime Text 3 Replace non-ASCII characters with a single space

Examples related to base64

How to convert an Image to base64 string in java? How to convert file to base64 in JavaScript? How to convert Base64 String to javascript file object like as from file input form? How can I encode a string to Base64 in Swift? ReadFile in Base64 Nodejs Base64: java.lang.IllegalArgumentException: Illegal character Converting file into Base64String and back again Convert base64 string to image How to encode text to base64 in python Convert base64 string to ArrayBuffer