Expo now provides a hashing method but only accepts String types for input.
Nodejs provides hashing of buffers/strings/arrays and can return the hashed value as a buffer as well .
The issue I am having is that I need to hash a buffer( uint8array ) in my app with sha256 . So I must find a way to convert it to a string, this causes issues because if I convert the buffer to anything else ex.( hexString,base64 ) my hash result is not equivalent to the exact value that nodejs crypto would provide.
have also tried converting the buffer to utf-8/16 strings but this causes issues because the chars in this format can have multiple bytes( issues with the number being above 127 ). So this path was incorrect as well.
My hashes must be equivalent to the traditional nodejscreateHash() results.
I am hitting a wall on this issue and not not find a way around it.
To complete my question, I am looking for a snipet to replace the following code without the crypto import and be able to hash Uint8Array.
export async function sha256(data) {
const hash = crypto.createHash('sha256');
hash.update(data); // data here is a Uint8Array !
const digest = hash.digest();
}
As reminder, expo-crypto handles only string and not Unit8Array