expo-crypto get different md5 & sha* hash from react-native-fs

  1. SDK Version: 38 (“expo”: “~38.0.8”,)
  2. Platforms(Android/iOS/web/all): Android (others not tested yet)

I need to get SHA1 or SHA256 to check a device camera roll image sent to OneDrive cloud.

expo-file-system provides a md5 hash via (FileSystem.getInfoAsAsync({md5: true}) for a 2KB jpeg image.

Using react-native-fs (hash method), I got the same expo-file-system md5 digest
react-native-fs.hash also gets same OneDrive API sha1.

When I try to get same md5 and sha1 using expo-crypto, it returns different HEX values.

Example of use:

const _pickImage = async () => {
        try {
            let result = await ImagePicker.launchImageLibraryAsync({
                mediaTypes: ImagePicker.MediaTypeOptions.All,
                base64: true
            if (result) {
                const digest = await Crypto.digestStringAsync(
                    { encoding: CryptoEncoding.HEX }
                console.log("picker.digest=", digest);
        } catch (error) {


It looks to me like you are calculating the MD5 hash of the Base64-encoded image instead of the image itself.

Thanks for replying.

I tried Base64.atob, but it didn’t return the correct md5.

const digest = await Crypto.digestStringAsync(
{ encoding: CryptoEncoding.HEX }

result.base64 contains no prefix (e.g. ’ data:image/png;base64,’), just image base64 data.
Neither Base64.btoa(b64toBlob(result.base64)) nor Blob data (using fetch().blob() and FileReader().readAsText) has worked as well.

I didn’t find how to get raw image data from expo components or decode base64. Another approach?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.