blog-examples
blog-examples copied to clipboard
Probably a bug
It seems to me there is a bug in the base64 decode. How could (enc3 == 64) on line 88, since you removed all paddings on line 59? enc3 can never be 64 so that check seems unnecessary.
Similarly, the line enc4 = this._keyStr.indexOf(input.charAt(j++)); seems wrong. If j>input.length, then input.charAt() = "" and indexOf("") =0, which is wrong since indexOf("A") = 0 as well. But your code works because in this case, i is already equal to bytes, so writing to uarray[i+1] writes outside of the actual array so it adds no new characters there.
https://github.com/danguer/blog-examples/blob/7614928e5f0968e078db2b0f2ac3624c96f9c7d5/js/base64-binary.js#L88
it actually is a bug.
padding =
characters must not be stripped away before processing; otherwise the resulting output may have unwanted zero
bytes at the end of the array (as much as the =
stripped away)