简体   繁体   English

如何解码 base64 编码的字符串?

[英]How do I decode a base64 encoded string?

I am trying to "decode" this following Base64 string:我正在尝试“解码”以下 Base64 字符串:

OBFZDTcPCxlCKhdXCQ0kMQhKPh9uIgYIAQxALBtZAwUeOzcdcUEeW0dMO1kbPElWCV1ISFFKZ0kdWFlLAURPZhEFQVseXVtPOUUICVhMAzcfZ14AVEdIVVgfAUIBWVpOUlAeaUVMXFlKIy9rGUN0VF08Oz1POxFfTCcVFw1LMQNbBQYWAQ== obfzdtcxcxlckhdxcq0KMqhkph9Uigyiaigyiaqxalbtzawueozcueew0dmo1kbpElwcvk vk1sfksfksflllaunosii fllaulppzsfllai fllppzsseqvefpppoyii ic inosity ofimainiafi ostpequiibsimostio flmaii ic flosioftppefmainitymosiogaiogaiogaiogaiogaiogaiogaiogaio flliopsioftppefmain forlosiovefmainitys

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. ".代码中的p1部分应该是字符串“ _p0lizei. ”。

  2. It is then converted to a Base64 string by the following code:然后通过以下代码将其转换为 Base64 字符串:

     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?问题是,如何解码 Base64 字符串,以便找出原始字符串是什么?

Simple:简单的:

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

The m000493 method seems to perform some kind of XOR encryption. m000493方法似乎执行某种 XOR 加密。 This means that the same method can be used for both encoding and decoding the text.这意味着可以使用相同的方法对文本进行编码和解码。 All you have to do is reverse m0001cd :您所要做的就是反转m0001cd

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

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

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

    // 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);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM