Hi @Adeel Mirza ,
The input is not a valid Base-64 string as it contains a non-base 64 character
The exact reason you're getting such an error is because it's not a valid Base64 string.
The Convert.FromBase64String(String) method converts the specified string to an equivalent array of 8-bit unsigned integers that encodes binary data as base-64 numbers.
FormatException
The length of string, ignoring white-space characters, is not zero or a multiple of 4.
The solution is that you need a string length divisible by 4, otherwise you pad it with equal signs.
if (encodedData.Length % 4 != 0)
encodedData += new String('=', 4 - encodedData.Length % 4);
-or-
The format of string is invalid. string contains a non-base-64 character, more than two padding characters, or a non-white space-character among the padding characters.
encodedData = encodedData.Replace('#', '=');
If there are special characters that need to be replaced, note that there can only be at most two padding characters
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.