Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

423
Views
JavaScript convert UTF-8 to base64

When I try to run the JS script below get an exception in the code:

var encode = window.btoa('Hiroto √')

"@lehesamudi.js:14:26
b.render/<@https://static.jsbin.com/js/prod/runner-4.1.8.min.js:1:13924
a.use/<@https://static.jsbin.com/js/prod/runner-4.1.8.min.js:1:10866
"
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You will need to encode the character first using the encodeURI function because it's not currently in the correct charset range for encoding using btoa.

I.e

window.btoa(encodeURI('Hiroto √')) => SGlyb3RvJTIwJUUyJTg4JTlB

To decode:

decodeURI(window.atob('SGlyb3RvJTIwJUUyJTg4JTlB')) => Hiroto √

about 4 years ago · Juan Pablo Isaza Report

0

Try to escape before, please find the code below.

function encode(str) {
    return window.btoa(unescape(encodeURIComponent(str)));
}

function decode(str) {
    return decodeURIComponent(escape(window.atob(str)));
}

// Usage:
encode('Encode me with UTF-8 char: ∑ßåœ ≈ ∆c') // "RW5jb2RlIG1lIHdpdGggVVRGLTggY2hhcjog4oiRw5/DpcWTIOKJiCDiiIZj"
decode("RW5jb2RlIG1lIHdpdGggVVRGLTggY2hhcjog4oiRw5/DpcWTIOKJiCDiiIZj") //'Encode me with UTF-8 char: ∑ßåœ ≈ ∆c'
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!