Error while decoding. The input is not a valid base-64 string as it contains a non-base 64 character
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
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);