I'm attempt to convert a base64 string generated from javascript code using C# code, but I'm running into an invalid length message.
The string is MQA5ADIAMwA3ADgANwA6ADAA0
It should convert back to 1923787:0
I tried a number of online decoders and some of them worked but a couple failed with the same invalid length error. I'll not post links here, but needless to say they were able to convert it back to the expected string.
C# Decode
var t = "MQA5ADIAMwA3ADgANwA6ADAA0";
var x = Convert.FromBase64String(t);
Javascript encoder:
var encoder = function (mL) {
if (!mL || mL === '') {
return '';
}
var ei = [];
var V;
for (V = 0; V < mL.length; V++) {
ei.push(mL.charCodeAt(V) % 256);
ei.push(Math.floor(mL.charCodeAt(V) / 256));
}
ei.push(0);
ei.push(0);
var sf = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';
var gF = [],
hO;
for (V = 0; V < ei.length - 1; V += 3) {
hO = ei[V] * 0x10000 + ei[V + 1] * 0x100 + ei[V + 2];
gF.push(sf.charAt(Math.floor(hO / 0x40000)));
gF.push(sf.charAt(Math.floor(hO / 0x1000) % 0x40));
gF.push(sf.charAt(Math.floor(hO / 0x40) % 0x40));
gF.push(sf.charAt(hO % 0x40));
}
var vr = Math.ceil(mL.length * 16 / 6);
while (gF.length > vr) {
gF.pop();
}
if ((gF.length % 4) === 3) {
gF.push('1');
} else if ((gF.length % 4) === 2) {
gF.push('2');
} else if ((gF.length % 4) === 0) {
gF.push('0');
}
return gF.join('');
};