Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SHA256 in React Native

I need to calculate SHA256 hash value of many files in Android and iOS using React Native. When files are selected by a user, my app will start calculating SHA256 for each file.

For web pages, I have been using crypto-js. But for Andoid and iOS applications, I am concerned that performance of crypto-js may not be fast enough as a file (eg. video file) may be >400 MB.

Is there any way that I can call Android/iOS native api to calculate SHA256, instead of using crypto-js for performance sake?

like image 651
user3390906 Avatar asked Oct 28 '25 14:10

user3390906


1 Answers

There isn't anything built into react-native itself to natively calculate a sha-256, but there are a few options.

As @Morre pointed out, react-native-sha256 is an open source project that supports calculating the sha-256 of a string using native components.

Another open source react-native project - react-native-fs - has support for calculating the sha-256 of a file using native components, specifically the hash function.

As @Morre has pointed out, you could write your own native code to provide the same functionality if you would prefer that option. Both of the libraries I mentioned here are open source, so the source code there can be a good reference for what the specific Android/iOS code would need to be written. There are also code examples here on StackOverflow for both java and swift. React-Native's native module documentation (Android) and iOS is extensive.

like image 148
davidpricedev Avatar answered Oct 30 '25 14:10

davidpricedev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!