Expo React Native String to BigInt

Viewed 158

I am trying to get unique ID for my device and I get is successfully with Constants.deviceId. However, I need it in 8 bytes (BigInt type). Is it possible somehow?

Device ID in string looks like this: "AAAAAAAA-BBBB-CCCC-DDDD-EEEEFFFFGGGG"

Is it better to use another approach and just generate a random 8 byte number and use it as unique ID for the device?

1 Answers

Can you encode it as base64?

yarn add Base64.

import Base64 from 'Base64';
 
const encoded = Base64.btoa('AAAAAAAA-BBBB-CCCC-DDDD-EEEEFFFFGGGG');
const decoded = Base64.atob(encoded);

// Should return QUFBQUFBQUEtQkJCQi1DQ0NDLUREREQtRUVFRUZGRkZHR0dH

npm package.
Blog with more info

Related