解密视频文件并播放而不保存 [英] decrypt a video file and play it without saving

查看:76
本文介绍了解密视频文件并播放而不保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一位客户想通过USB对视频进行复制保护,为此我想到了以下方法:

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

1)加密视频文件.

2)将加密文件放入USB.

2) Putting the encrypted file in USB.

3)解密程序,用于对加密文件进行解密.

3) A decryption program that decrypt the encrypted file.

4)从解密的文件中获取视频.

4) Getting the video from decrypted file.

5)最后播放视频.

我已经成功对视频进行了加密(xyz.enc文件),也已解密(xyz.dnc).现在,我不知道如何从解密的文件中获取视频并在不存储的情况下播放.我花了3个小时在Google上进行搜索,但没有发现任何东西.我正在ASP.net&C#.

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#.

推荐答案

我已经在C#中使用SHA1算法对视频进行了加密和解密

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);
    }

这篇关于解密视频文件并播放而不保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆