I Tried as below using libmedia library (http://libeasy.alwaysdata.net/) : But the encrypted video doesn't decrypt and play with the same key and cipher. Pls. see my code below: (Modified for easy understanding)
public class MyClassActivity extends Activity {
VideoView mVideoView;
LocalSingleHttpServer mServer ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SecretKey sk = encryptVideo("/mnt/sdcard/input.mp4", "/mnt/sdcard/enc.mp4");
playENCVideo(sk,"/mnt/sdcard/enc.mp4");
}
public void playENCVideo(SecretKey skey, String path) {
Cipher decipher = null;
decipher = Cipher.getInstance("AES");
decipher.init(Cipher.DECRYPT_MODE, skey);
mServer = new LocalSingleHttpServer();
mServer.setCipher(decipher);
mServer.start();
path = mServer.getURL(path);
mVideoView = (VideoView) findViewById(R.id.vid_view);
mVideoView.setVideoPath(path);
mVideoView.setOnPreparedListener(this);
mVideoView.setOnCompletionListener(this);
mVideoView.setMediaController(new MediaController(this));
mVideoView.start();
} //playENCVideo()
encryptVideo() {
}
decryptVideo() {
}
} //MyClassActivity
My observations:
- With smaller MP4 files, atleast the unencrypted video plays from the local http server
- With larger MP4 files, uncencrypted video also doesn't play
- With smaller files, the encrypted file doesn't play with the Cipher based on the same key that used for encryption.
- I can confirm that my encryption and decryption with AES/RC4 works well. I can play decrypted files normally from a player.
Please help me in using the correct way of using libmedia API for playing encrypted video