Base64/32/16 encoding/decoding for React Native written in C/C++ and JSI
source link: https://reactnativeexample.com/base64-32-16-encoding-decoding-for-react-native-written-in-c-c-and-jsi/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Base64/32/16 encoding/decoding for React Native written in C/C++ and JSI
react-native-jsi-base-coder
Base64/32/16 encoding/decoding for React Native written in C/C++ and JSI.
Installation
React Native
yarn add react-native-jsi-base-coder
expo install react-native-jsi-base-coder
expo prebuild
Usage
Default behavior is using the base64Rfc4648
algorithm to encode/decode the data.
import { encode, decode } from 'react-native-jsi-base-coder';
// With the default algorithm in `base64Rfc4648`.
encode('Hello World!'); // SGVsbG8gV29ybGQh
decode('SGVsbG8gV29ybGQh'); // Hello World!
// With the Base32 algorithm with the `base32Rfc4648`.
encode('Hello World!', { algorithm: Algorithm.base32Rfc4648 }); // JBSWY3DPEBLW64TMMQQQ====
decode('JBSWY3DPEBLW64TMMQQQ====', { algorithm: Algorithm.base32Rfc4648 }); // Hello World!
encode
function (stringToEncode: string, config?: Config): string
Takes a string and returns an encoded string.
decode
Takes an encoded string and returns a decoded string.
function (bytesToDecode: string, config?: Config): string
config
The config object only take one property algorithm
to define how you want to encode/decode your data. The default algorithm used is base64Rfc4648
.
enum Algorithm {
'base64Rfc4648' = 'base64Rfc4648',
'base64Url' = 'base64Url',
'base64UrlUnpadded' = 'base64UrlUnpadded',
'base32Rfc4648' = 'base32Rfc4648',
'base32Crockford' = 'base32Crockford',
'base32Hex' = 'base32Hex',
'base16Upper' = 'base16Upper',
'base16Lower' = 'base16Lower',
}
encode('string to encode', { algorithm: Algorithm.base32Crockford });
Example
To run the development example you can use the following command:
cd example
yarn
Acknowledgements
- Thanks to Marc for his JSI template react-native-jsi-library-template.
- Thanks to cppcodec for the C implementation.
License
GitHub
Challenge: React Native Concepts
(Unofficial) React Native package for Bitmovin SDK 3+ and React Native 0.67
Subscribe to React Native Example for Android and iOS
Get the latest posts delivered right to your inbox
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK