Is it possible to encrypt downloaded files (expo-file-system) with Expo ?

Does anyone know, if it is possible (and how) to encrypt files downloaded with expo-file-system and decrypt them before previewing?

I want to create an extra security layer for my App: if a device is stolen (and pin code is known), bad guys won’t be able to get the app files easily.

If someone had a similar issue or has any ideas regarding the topic, please share your knowledge with me.

Expo SKD 35

Hey @mtshv,

We have no built-in way to encrypt/decrypt with the FileSystem module. We do offer a Crypto module ( that you could leverage but as for the implementation, the onus will be on you.


Hi @adamjnav. The documentation only mentions digests, not encryption/decryption. Is the documentation incomplete?

@mtshv, unless the expo-crypto docs are incomplete it seems that you would have to implement this yourself, unless the file contents are small enough to store in SecureStore.

One of the libraries listed here might work for you, but I have not tried any of them. Since they are not designed for React Native/Expo, some of them might not work at all.

1 Like

@adamjnav, @wodin
Thank you both for your answers.

@wodin I double your question regarding the lack of actual encryption/decryption functionality in the Crypto module. For example, I need to use aes encryption.

Some extra info on what I want to achieve:

Basically I am looking for a way of encrypting binary video files in order to store it in the filesystem. + a way to decrypt them before playback in <Video />

My investigation led me to the following conclusions:

  • expo-file-system does not allow to pass a file as a binary argument to encrypting functions

  • available js-encrypting solutions are expecting string (plaintext) as input

  • there is a way to convert video binary to a plain text ex: base64. But there seems to be no reasonable solution of converting video file back to binary, ex: .mp4 from a plain text.

  • <Video /> does not accept data:video/mp4;base64, as a valid source.

  • I attempted to create blob (ArrayBuffer) from Base64, it was not recognized as a valid video source.
  • I attempted to save .mp4 file as .txt in order to encode/decode and save again as .mp4 but txt-extension in this case was not recognized, due to encoding.

Please correct me if I am wrong, or confirm my statements if you can.

I would like to understand if it is possible to achieve, what I want with the Expo managed workflow, or I need to eject to bare react-native.

If anyone has any ideas/suggestions/advices, please share :pray:

The following is not based on any experience with trying to do something like this, so if anyone has other ideas it would be great if they could post them.

Just a possible clarification. Plaintext in cryptography just means unencrypted data. It could be binary data. Of course maybe the libraries you’re referring to do need actual 7-bit ASCII/UTF-8/etc. text. If you know this already, sorry for explaining, but it wasn’t clear to me from your message.

About expo-crypto: I’ve just run git grep -i aes in the packages/expo-crypto directory with no results.

Based on your requirements I think you will likely have to eject and implement your own video module/component. Otherwise I don’t see how it could work. You presumably don’t want to decrypt the video to a plaintext .mp4 file, play that, and then delete it afterwards? If not, then you’ll need a video component that can decrypt it on the fly. And I don’t see that happening without implementing it yourself (unless you’re lucky and find that someone else has already done it, but either way I think you’re going to have to eject.) If you don’t mind decrypting to a plaintext file, playing that and then deleting it again afterwards, then maybe you won’t need to eject. However, that will leave unencrypted data around on the flash, even though the filesystem thinks of it as deleted, that could potentially be retrieved. You might also need to watch out for the video component or the OS making an thumbnail of the unencrypted video.

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