输入不是有效的 Base-64 字符串,因为它包含非 64 位字符,即使其他资源可以处理字符串 [关闭]

问题描述 投票:0回答:0

目标是将 base64 解码为二进制。

我试过的

public static byte[] Decode(string input)
{
    string cleanedInput = Regex.Replace(input, @"[^a-zA-Z0-9\+/=]", ""); // Entfernt alle ungültigen Zeichen
    int paddingLength = cleanedInput.Length % 4;
    if (paddingLength != 0)
    {
        paddingLength = 4 - paddingLength;
        StringBuilder paddedInput = new StringBuilder(cleanedInput);
        paddedInput.Append(new string('=', paddingLength));
        cleanedInput = paddedInput.ToString();
    }
    byte[] bytes = Convert.FromBase64String(cleanedInput); // Konvertiert den bereinigten String in Bytes

    return bytes;
}

我明白了

The input is not a valid Base-64 string as it contains a non-base 64 character.

使用https://www.base64decode.org/我可以很容易地解码相同的字符串。

c# base64
© www.soinside.com 2019 - 2024. All rights reserved.