-2

I am trying this code in java, as android internally uses java as well. My question is about how do I corrupt (encrypt) a mp4 video, so that even if some body copies those videos, it wouldn't play.

I tried corrupting a mp4 video by adding "hi" to ending location of that file, so that the file be corrupted and vlc player can't play it. I could able to successfully corrupt the video. VLC no more able to play video.

While decrypting we are reading the content except last 2 characters "hi" from that file, and copied the content into another file, to check if I can decrypt properly. But problem is de-crypted video is not playing properly.VLC is not reporting any error, but a green color window is shown in place of video, sound is also not coming. After decrypting the size of the file is proper as expected.

My doubt is when I am reading the data of mp4 file and copying into other file, some how mp4 file properties are missing, that is the reason why vlc might not be able to play the way it is supposed to play.If that is the case, Are there any ways to set mp4 properties manually to a decrypted file, so that vlc can play it properly?

I know that there are many cipher classes to do this, but unfortunately encrypting and decrypting a video file of size 50mb could be too slow. I don't want a delay of more than 5 seconds to my video users.I tried already cipher but it is slow, taking more than 30 seconds some times which might irritate genuine video users who paid for the videos.

I just want a very light weight security model, which can protect my videos to some extent (As you know locks are not meant for thieves).

If any tried a simple algorithm like this, to corrupt mp4 video manually and decrypt on the fly before playing, please help me. Apart from this we are also hiding the files, changing the extension of the file, and splitting a video into smaller files which will be merged through our application just before playing.

My code which i tried, pasting here.

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.DosFileAttributes;


public class Testing {
    public static void main(String[] args) {
        File file = new File("e:/ascii.mp4"); //original file path
        File file2 = new File("e:/satish.mp4"); //encrypted file path
        File file3 = new File("e:/satish2.mp4"); //decrypted file path
        try {

            String s = new String(Files.readAllBytes(file.toPath()));
            s = s+"hi"; //appending hi to mp4 content
            FileWriter fw = new FileWriter(file2);
            fw.write(s); //writing mp4 content + hi to encrypted file
            fw.close();

            String s2 = new String(Files.readAllBytes(file2.toPath()));
            s2 = s2.substring(0, s2.length()-1-2); //reading content except last 2 characters.

            FileWriter fw2 = new FileWriter(file3); //decrypted file
            fw2.write(s2); //writing content to decrypted file.
            fw2.close();

        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}
user1923551
  • 4,684
  • 35
  • 29
  • Digital Rights Management systems are designed to do this exact thing efficiently. Try looking into DRM systems available for MP4 files on Android. – Stig Tore Oct 13 '15 at 09:27

1 Answers1

0

Finally I could able to get the solution for this. I used the logic of this question. with little modifications which I specified there in that link itself. I could able to decrypt my 52 mb video in just 4 seconds.

Community
  • 1
  • 1
user1923551
  • 4,684
  • 35
  • 29