I'm developing a website in Javascript. I've already made the backend using a REST api. To login on the server I have to decode a base64 string. Once decoded it should be just a binary string (not a simple text string, a binary string)
The problem is that when I do
function base64_decode(string) {
return decodeURIComponent(Array.prototype.map.call(atob(string), function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
I have this error : URIError: URI malformed
.
In addition with atob
and btoa
I've had wrong base64 strings.
I've tried many different algorithms, with many different packages and it still does not work. Is it possible in Javascript to decode a base64 encoded binary string ?
I've used the same thing for the iOS application and with Swift it works fine. It works also fine in Java. I just struggle with Javascript on the base64 decoding.
An example of a string I'm trying to decode
lYlRMvG3MuhOqjmCPAHnoQmEH/TS087iZj9zt6vMG+nJhRsaqr/oTw+drfM+KAEx1xwWbFu6WGB8uEyKPZLb7n9f5mToKiLf8gVVBpogGsI8/EYz3xsxSbLjLby8+FSLNYV8HA4Ct6N5oGEVyM58CY+HwuKZ0T6k7r+t1NDU584=