Javascript Base64 Encode, Decode for UTF-8/unicode string

Complete article that works for me : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding 

Part where we encode from unicode/utf-8 is

function utf8_to_b64( str ) {
  return window.btoa(unescape(encodeURIComponent( str )));
}
 
function b64_to_utf8( str ) {
  return decodeURIComponent(escape(window.atob( str )));
}
 
// Usage:
utf8_to_b64('✓ à la mode'); // "4pyTIMOgIGxhIG1vZGU="
b64_to_utf8('4pyTIMOgIGxhIG1vZGU='); // "✓ à la mode"

 This is one of most used thing now a days.


One Response

  1. Amir
    Amir September 7, 2015 at 11:25 AM |

    Well hello, I should say here that escape is going to be dropped.
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape
    Please share a solution without using escape.
    thanks


Comments are closed.