decrypt a video file and play it without saving

2020-07-26 10:38发布

问题:

One of my client wants to make video copy-protected in USB, for which I have thought of the following way:

1) Encrypt the video file.

2) Putting the encrypted file in USB.

3) A decryption program that decrypt the encrypted file.

4) Getting the video from decrypted file.

5) Finally playing the video.

I have succesfully encrypted a video (xyz.enc file) , and decrypted too (xyz.dnc). Now, I don't know how to get the video from that decrypted file and play it without storing . I have spent 3 hours searching on Google but haven't fount anything. I am working in ASP.net & C#.

回答1:

To copy-protect a video file, the best way to accomplish it used to be apply DRM to it. That way you can restrict how may times it should play or how long it should be available to the user, but that still could be broken via a lot of means.

You cannot make any video 100% copy protected. Please read the article below. If that was the case, the hollywood movies wouldnt be freely available via the torrent networks.

http://www.streamingmedia.com/Articles/Editorial/Featured-Articles/DRM-Is-Dead-79353.aspx



回答2:

This is a quite old topic but the task seems to be still actual for developers.

As people said 100% copy protection is impossible but you can make hacked work harder.

The idea is to intercept file calls like ReadFile, SetFilePointer and provide decrypted data to the player, please read a tutorial here: http://boxedapp.com/encrypted_video_streaming.html



回答3:

I have done encryption and decryption of a video using SHA1 algorithm in C#

  var actualFilepath= "D:\\Video\\Sample.mp4";
  var videoBytes=ConvertVideoToBytes(actualFilepath);
  var encryptedvideoBytes=EncryptVideo(videoBytes);
  ConvertEncryptFileToFile(encryptedvideoBytes);
  var encryptedFilepath = "D:\\Video\\VideosEncryptedFile.deific";
   var readVideoBytes = ConvertVideoToBytes(encryptedFilepath);
   var decryptedVideoBytes = DecryptVideo(readVideoBytes);
   ConvertDecryptFileToFile(decryptedVideoBytes);



  private byte[] ConvertVideoToBytes(string filePath)
  {            
   return System.IO.File.ReadAllBytes(filePath);            
  }


   private byte[] EncryptVideo(byte[] videoBytes)
   {
        string passPhrase = "mypassphrase27092019";
        string saltValue = "mysaltvalue";
        RijndaelManaged RijndaelCipher = new RijndaelManaged();
        RijndaelCipher.Mode = CipherMode.CBC;
        byte[] salt = Encoding.ASCII.GetBytes(saltValue);
        PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, salt, 
     "SHA1", 2);
        ICryptoTransform Encryptor = 
        RijndaelCipher.CreateEncryptor(password.GetBytes(32), password.GetBytes(16));

        MemoryStream memoryStream = new MemoryStream();
        CryptoStream cryptoStream = new CryptoStream(memoryStream, Encryptor, 
        CryptoStreamMode.Write);
        cryptoStream.Write(videoBytes, 0, videoBytes.Length);
        cryptoStream.FlushFinalBlock();
        byte[] cipherBytes = memoryStream.ToArray();

        memoryStream.Close();
        cryptoStream.Close();

        return cipherBytes;
    }


    private void ConvertEncryptFileToFile(byte[] encryptedvideoBytes)
    {
        var filePath = string.Empty;
        filePath = "D:\\Video";
        System.IO.File.WriteAllBytes(filePath+"\\VideosEncryptedFile.deific", 
     encryptedvideoBytes);
     }


    private byte[] DecryptVideo(byte[] encryptedVideoBytes)
     {
        string passPhrase = "mypassphrase27092019";
        string saltValue = "mysaltvalue";

        RijndaelManaged RijndaelCipher = new RijndaelManaged();

        RijndaelCipher.Mode = CipherMode.CBC;
        byte[] salt = Encoding.ASCII.GetBytes(saltValue);
        PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, salt, "SHA1", 2);

        ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(password.GetBytes(32), password.GetBytes(16));

        MemoryStream memoryStream = new MemoryStream(encryptedVideoBytes);
        CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read);
        byte[] plainBytes = new byte[encryptedVideoBytes.Length];

        int decryptedCount = cryptoStream.Read(plainBytes, 0, plainBytes.Length);

        memoryStream.Close();
        cryptoStream.Close();

        return plainBytes;
    }


  private void ConvertDecryptFileToFile(byte[] decryptedVideoBytes)
    {
        var filePath = string.Empty;
        filePath = "D:\\Video";
        System.IO.File.WriteAllBytes(filePath + "\\FinalFile.mp4", 
        decryptedVideoBytes);
    }