Base64 Encoding of utf-8 encoded string using Javascript

Posted on 13-03-2017 by Nadir Latif


The btoa function encodes a string using Base64 encoding scheme. If the string is utf-8 encoded then the btoa function will not work correctly. The solution is to first url encode the string then call window.btoa function.

To url encode a string we can use the encodeURIComponent function. to url decode a string we can use the decodeURIComponent function