为了账号安全,请及时绑定邮箱和手机立即绑定

Convert.FromBase64String() 抛出“无效的 Base-64 字符串”错误

Convert.FromBase64String() 抛出“无效的 Base-64 字符串”错误

C#
隔江千里 2021-06-27 11:31:24
我有一个 Base64 编码的密钥。在尝试解码时,我收到以下错误。错误是由byte[] todecode_byte = Convert.FromBase64String(data);base64Decode 中的错误输入不是有效的 Base-64 字符串,因为它包含非 base 64 字符、两个以上的填充字符或填充字符中的非法字符。我正在使用以下方法来解码:public string base64Decode(string data){    try    {        System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();        System.Text.Decoder utf8Decode = encoder.GetDecoder();        byte[] todecode_byte = Convert.FromBase64String(data); // this line throws the exception        int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);        char[] decoded_char = new char[charCount];        utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);        string result = new String(decoded_char);        return result;    }    catch (Exception e)    {        throw new Exception("Error in base64Decode" + e.Message);    }}
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 1132 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号