itinance / react-native-sha256

sha256 natively for react-native
MIT License
99 stars 50 forks source link

[Feature request] Raw & Base64 support #23

Open halaei opened 4 years ago

halaei commented 4 years ago

Is it possible to provide raw, base64, and/or base64url output support as well. This is will be handy for implementing OAuth clients, for example.

halaei commented 4 years ago

I find this simple snippet from stackoverflow to convert hex to base64:

btoa("4142434445464748494a4b4c4d4e4f505152535455565758595a".match(/\w{2}/g).map(function(a){return String.fromCharCode(parseInt(a, 16));} ).join("")) 

It is going to fix my problem. Thanks.

sevaa commented 1 year ago

The following works for me as of React Native 0.70.5:

function hexToBase64(s:string)
{
  return Buffer.from(s, 'hex').toString('base64');
}
Beat-YT commented 7 months ago

it would still be nice to have support for base64 straight from the module.