我运行此代码时有例外,什么是错误的
var encoder = new System.Text.UTF8Encoding();
System.Text.Decoder utf8Decode = encoder.GetDecoder();
byte[] todecodeByte = Convert.FromBase64String(encodedMsg);
int charCount = utf8Decode.GetCharCount(todecodeByte, 0, todecodeByte.Length);
var decodedChar = new char[charCount];
utf8Decode.GetChars(todecodeByte, 0, todecodeByte.Length, decodedChar, 0);
var message = new String(decodedChar);
例外情况发生在此行中
byte[] todecodeByte = Convert.FromBase64String(encodedMsg);
base64编码每个字符6位。因此,字符串的长度乘以6,必须除以8。
如此好的赔率,以至于 encodedmsg 只是一个正确编码的base64字符串。您可以附加一些=字符以绕过异常,并查看是否有任何可识别的弹出。=字符是base64的填充字符:
while ((encodedMsg.Length * 6) % 8 != 0) encodedMsg += "=";
// etc...