lyubo / react-native-sodium

ISC License
61 stars 46 forks source link

crypto_box_easy #21

Closed tmp05 closed 5 years ago

tmp05 commented 5 years ago

Hello, in sodium when I use crypto_box_easy for message '123456' I get the result_bytes.length=22 bytes ( 6 + 16 (crypto_secretbox_macbytes) ) result_string.length=44 symbols,

but here I get the result_string.length=23 symbols, why?

lyubo commented 5 years ago

Binary data can't pass the native-javascript bridge. Therefore all libsodium bindings on JS side pass byte[] type arguments as Base64 strings. If you want to manipulate returned binary data in JS, than you have to decode it first

tmp05 commented 5 years ago

ok, I get from crypto_box_easy(..) result_string=ZdMXI43U2fQZGP65f3NYNcTEwrQ= so, if I use base64.decode( base64 from 'react-native-base64' ) or atob() my result_decoded = eÓ#ÔÙôþ¹sX5ÄÄ´ can you help me how to decode correctly?

tmp05 commented 5 years ago

the decision is: import Buffer from 'buffer' Buffer.Buffer.from(result_string,"base64") it gives array byte[]