I have encrypted a video file using base64 encoding format and AES-encryption. I decrypt data stream-by-stream and append/write each stream (as a .mp4 file) to achieve the final video but it takes a lot of time to achieve a final output.
Major Edit:
I have found resources html5-media-and-data-uri which helps to play data in a webview
, but it doesn't play videos with 2,000,000+ base64 characters.
Function to decrypt a file and initialize HTML code within web view with base64 data
decryptfile() {
RNFetchBlob.fs
.readStream(
RNFetchBlob.fs.dirs.DCIMDir + "/encryptfile1.dat",
"base64",
2796256, //character to be read at a time for decryption
2500 // Time taken before each stream enters for decryption
)
.then(stream => {
let data = "";
stream.open();
stream.onData(chunk => {
var decipherText = simpleCrypto.decrypt(chunk.toString()); // Decryption
decryptText = decryptText + decipherText; // appending decrypted data
});
stream.onEnd(() => {
htmlCode =
`<html>
<body>
<video style="width: 50%; height: 50%; margin-top: 10%; margin-left: 22%;"
controls>
<source type="video/mp4" src="data:video/mp4;base64,` +
decryptText.toString() + // final decrypted data
`">
</video>
</body>
</html>`;
this.setState({ playvideo: !this.state.playvideo }); // state set for playing video at end of decryption
console.log("File decrypted");
});
});
}
Web View Code
<WebView
style={{ flex: 1 }}
source={{ html: htmlCode }}
/>
Need help in finding ways/alternatives to play videos from base64 in react-native.
This is an Offline e-learning app where videos are stored on SD-CARD and data is decrypted on the fly and played in a video player.