Native decoded base64 encoding

I am trying to decode a base64 encoded string token in a native reaction, atob does not work, and a library like js-base64 does not resolve the problem.

Does anyone have a solution?

+9
source share
3 answers

atob and btoa are not supported in the JavascriptCore, but work when the application is running under the Chrome debugger, because the JS code runs in Chrome when debugging. There are many basic modules. https://github.com/mathiasbynens/base64 works great for me.

+11
source

I found some simple way for me, the same api as node.

Set yarn add buffer

Usage: console.log(Buffer.from("Hello World").toString('base64')); console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii')); console.log(Buffer.from("Hello World").toString('base64')); console.log(Buffer.from("SGVsbG8gV29ybGQ=", 'base64').toString('ascii'));

+10
source

Another way is to install this react-native-base64 package and use it as shown below in the response to native.

npm install --saveact-native-base64

 import base64 from 'react-native-base64' base64.encode('Some string to encode to base64'); base64.decode('VGhlIG51bWJlciBpcyA2MDAwMCwgd2hpY2ggY2FuIGJlIHJlYWQgYXMgc2l4dHkgdGhvdXNhbmQuJm5ic3A7PEJSPg==') 
0
source

Source: https://habr.com/ru/post/1263152/


All Articles