react-native-aes
react-native-aes copied to clipboard
How to encrypt a Video File
Below is how to encrypt a text. Is there a way to encrypt video file by passing the path ?
const encrypt = (text, keyBase64) => { var ivBase64 = "base64 random 16 bytes string"; return Aes.encrypt(text, keyBase64, ivBase64).then(cipher => ({ cipher, iv: ivBase64 })); };
same issue here. what is the basic idea to encrypt any kind of file ?
@Pruthvirajcodewave @nabeelItilite you've likely moved on from this by now, but with the current API you'd need to load the entirety of the file from disk into a base64 string and then pass it across the bridge to be encrypted. I don't recommend doing this, as it'd be quite slow.
I need to encrypt media files in the app I'm working on, so even though it'll take some native work, I plan to fork this repository, and add a couple of native functions on both the iOS and Android sides for encrypting files on-disk, without having to go across the JS bridge. Luckily, @tectiv3 has already done almost all the work required for this, and it should be relatively simple to follow the existing code on each platform and make functions for encrypting files by path.
Each side would have to use native APIs to:
- Load the file from the path passed into an array buffer in memory
- Encrypt the data using the key and IV specified by the caller
- Write the encrypted data back to disk, maybe in a temp folder, or maybe alongside the original location with a new prefix
- Fulfill the result of the promise returned by the function with the path of the new file