How do I adapt the example in the Usage section to work in React Native?
See original GitHub issueimport crypto from 'isomorphic-webcrypto'
crypto.subtle.digest(
{ name: 'SHA-256' },
new Uint8Array([1,2,3]).buffer
)
.then(hash => {
// do something with the hash buffer
})
This does not work as is in React Native. I have tried the following, but I’m not really sure how to get the values into the digest function. I just want to prove it works as it should.
const view = new Int8Array( new ArrayBuffer(3));
crypto.subtle.digest(
{ name: 'SHA-256' },
view
)
.then(hash => {
// do something with the hash buffer
console.log('hash: ', hash);
});
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
React Native Navigation: Tutorial with examples
In this React Native Navigation tutorial, we'll show you some examples of navigation patterns you can implement with React Navigation.
Read more >Integration with Existing Apps - React Native
To use the power of autolinking, we have to apply it a few places. First add the following entry to settings.gradle : apply...
Read more >Introducing Hooks - React
Completely opt-in. You can try Hooks in a few components without rewriting any existing code. But you don't have to learn or use...
Read more >Accessibility - React
Sometimes we break HTML semantics when we add <div> elements to our JSX to make our React code work, especially when working with...
Read more >Integrating with Other Libraries - React
While it is generally recommended to use unidirectional data flow such as React state, Flux, or Redux, React components can use a model...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I added additional details about hashing to the README. I also included an example of how to generate a hash in the React Native examples.
It should return an
ArrayBuffer
. If you performtoString()
on that you’ll get something likeArrayBuffer []
. Brief explanation:An
ArrayBuffer
is an untyped array that just represents a chunk of memory with a defined length. In order to get a view of that memory, you have to cast it to a typed array. Often, this is aUint8Array
. The U makes it unsigned, so it’s alway positive and the 8 makes each element represent one byte.I imagine what you want is a SHA256 hash as a string. This is most commonly represented in hex. I wrote
hex-lite
to make this easy, so here’s an example: