Question FromBase64string - Invalid length of the string

miss14

New member
Joined
Oct 20, 2018
Messages
3
Programming Experience
Beginner
Hello everybody!
I have a string in base64, that I have to convert in a byte array. To do this, I use Frombase64string. But it give me an error about the wrong lenght of the string, that isn't a multiple of 4.
So I add to the string a simbol ( =) to get the correct lenght. But I have to add 3 character. I see that i can use only 2 = as padding character.
How can i do?
Thanks
 
Last edited:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,224
Location
Sydney, Australia
Programming Experience
10+
You should start with the data that you expect to get back and pass that to ToBase64String and see what it produces and compare that to what you have. That will then tell you what's missing. Have you read up about the base-64 format too? Where is this data coming from that it isn't valid?
 

miss14

New member
Joined
Oct 20, 2018
Messages
3
Programming Experience
Beginner
I see I can do
Regex regex = new Regex(@"==="); //simboli
string[] val = regex.Split("Y2F6em9vb29vb29vb29vb29vb28===");
Byte[] b = convert.frombase64string(val);

Is it right?
 
Top Bottom