I have classified data in my SD-CARD. Is there any way to give access to the SD-CARD only through the app(react-native-project) ? File involved is .mp4 files.
Most of the solutions that i have found were about encrypting the data within the SD-CARD using AES-Encryption. But i am dealing with large files, therefore decrypting the entire file at once will throw memory out exception.
Secondly, Reading entire data stream-by-stream is a possibility, when i tested this method out the first set of stream(encrypted) will get successfully decrypted. The next stream will result in the error Malformed UTF-8 data.
Thirdly, I have tried dividing the file into pieces, decrypting each piece and appending each them to make a expected file. I am getting issues as specified here Issue Description.
EDIT:
Package Used for encryption: simple-crypto-js,
Function to decrypt file stream-by-stream:
decryptfile() {
RNFetchBlob.fs
.readStream(
RNFetchBlob.fs.dirs.DCIMDir + "/encrypted.dat",
"base64",
4194303,
30000 // 30 seconds buffer time before next stream comes
)
.then(stream => {
let data = "";
stream.open();
stream.onData(chunk => {
data += chunk;
var decipherText = simpleCrypto.decrypt(chunk.toString());// First set of chunk will get successfully decrypted, the next chunk will result to Malformed UTF-8 data error
this.writeOriginal(decipherText);
});
stream.onEnd(() => {
console.log(data);
});
});
}
Function to append data:
writeOriginal(decipherText) {
RNFetchBlob.fs
.appendFile(
RNFetchBlob.fs.dirs.DCIMDir + "/encrypt.mp4",
decipherText,
"base64"
)
.then(() => {
console.log("File Written");
})
.catch(error => {
console.log("file writing error", error);
});
}
This is a Offline learning application where videos are stored in an SD Card and accessed in app.