Z
Z
Zefirot2022-01-12 17:02:17
C++ / C#
Zefirot, 2022-01-12 17:02:17

What causes "Invalid length for a Base-64 char array or string" to crash?

In this line crashes

string data = "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr";
byte[] buffer = Convert.FromBase64String(data);

FormatException: Invalid length for a Base-64 char array or string.
System.Convert.FromBase64_Decode(System.Char* startInputPtr, System.Int32 inputLength, System.Byte* startDestPtr,

in data as you can see, I placed a static test text, otherwise some symbols could be "littered" somewhere, but it gives me such an error.
In the net, they write everywhere that this is due to invalid characters, but at the moment I'm testing without any with a clean string, what's the matter then?

And it's strange that the same code used to work fine before ....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2022-01-12
@Zefirot

Because it's garbage, not Base64String. If you are going to test, then first you need to encode the garbage, and only then decode and compare with the original.
And then with the same success, you can save this html page to a file and change the file extension to .exe, and then wonder why the file does not start.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question