解码时出错。输入不是有效的base-64字符串,因为它包含非基本64个字符,超过两个填充字符 [英] Error while decoding. The input is not a valid base-64 string as it contains a non-base 64 character, more than two padding characters

查看:348
本文介绍了解码时出错。输入不是有效的base-64字符串,因为它包含非基本64个字符,超过两个填充字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以json格式得到来自api的响应,我已将json响应编码存储在表中。我想解码响应并对其进行解密。当我尝试解码数据时,收到错误。



错误:输入不是有效的Base-64字符串,因为它包含非基数64字符,两个以上的填充字符,或填充字符中的非法字符。



json中的实际响应:

I am getting response from api in json format which is encoded I have stored json response in a table.I want to decode response and deserilize it. When I am trying to decode the data ,getting error.

Error : The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

Actual Response in json :

data={"Id": "234", "Name": "pinky", "MobileNumber": "", "ClassName": "Class1_Physics",   "DOBTime": "1990-04-11 15:46:38", "Landline": "", "Status": "Unmarried"}





编码后:



After Encoding :

data%3D%7B%22Id%22%3A%20%22234%22%2C%20%22Name%22%3A%20%22pinky%22%2C%20%22MobileNumber%22%3A%20%22%22%2C%20%22ClassName%22%3A%20%22Class1_Physics%22%2C%20%20%20%22DOBTime%22%3A%20%221990-04-11%2015%3A46%3A38%22%2C%20%22Landline%22%3A%20%22%22%2C%20%22Status%22%3A%20%22Unmarried%22%7D%0A





我已经获得了解码工具之一的帮助。代码://获取存储在数据库中的响应并分配给名为'Name'的字符串





I have taken help of one of tool for decoding . Code : // Fetching response which was stored in database and assigning to string called 'Name'

string base64Decoded, base64Decoded2;
                base64Decoded = Name.Trim();
            base64Decoded = base64Decoded.Replace('-', '+');
            base64Decoded = base64Decoded.Replace('_', '/');
            base64Decoded = base64Decoded.Replace('=', '/');
            base64Decoded = base64Decoded.Replace(':', '/');
            byte[] data2 = System.Convert.FromBase64String(base64Decoded);
            base64Decoded2 = System.Text.ASCIIEncoding.ASCII.GetString(data2);







Getting error at this line :

byte[] data2 = System.Convert.FromBase64String(base64Decoded);





< b>我尝试了什么:





What I have tried:

string base64Decoded, base64Decoded2;
                base64Decoded = Name.Trim();
            base64Decoded = base64Decoded.Replace('-', '+');
            base64Decoded = base64Decoded.Replace('_', '/');
            base64Decoded = base64Decoded.Replace('=', '/');
            base64Decoded = base64Decoded.Replace(':', '/');
            byte[] data2 = System.Convert.FromBase64String(base64Decoded);
            base64Decoded2 = System.Text.ASCIIEncoding.ASCII.GetString(data2);

推荐答案

Quote:

解码时出错。输入不是有效的base-64字符串,因为它包含一个非基本的64个字符,两个以上的填充字符

Error while decoding. The input is not a valid base-64 string as it contains a non-base 64 character, more than two padding characters



消息告诉你所有,你收到错误消息,因为< b>您的输入不是base64编码。

只需将编码数据与解码数据进行比较,如果仔细观察,有些部分会被编码而其他部分则不会被编码。


The message tell you all, you get the error message because your input is not base64 encoded.
Just compare encoded data with decoded, if you look carefully, some parts are encoded and others are not.

data=  {  "  Id"  :     "  234"  ,     "  Name"  :     "  pinky"  ...
data%3D%7B%22Id%22%3A%20%22234%22%2C%20%22Name%22%3A%20%22pinky%22...



您只需要替换其他人。


you just have to replace the ones by the others.


这篇关于解码时出错。输入不是有效的base-64字符串,因为它包含非基本64个字符,超过两个填充字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆