【问题标题】:How to Play decrypted file如何播放解密文件
【发布时间】:2014-01-22 07:26:03
【问题描述】:

对于视频的版权保护,我想到了

Step-1) 使用密钥加密视频文件。

步骤 2)解密文件或在内存流中解密。

Step-3) 播放解密文件或从内存流播放。

我已经成功地用密钥加密和解密了一个视频文件。但不知道如何播放解密文件(.dnc文件)。

谁能帮我播放解密后的视频文件(文件或内存流)。

解密代码

 private void Decryption(string filePath)
        {
            try
            {
                DateTime current = DateTime.Now;
                string encName = filePath + "data" + ".enc";
                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

                #region Seperate key and data
                byte[] alldata = File.ReadAllBytes(filePath);
                byte[] getencryptedkey = new byte[128];
                byte[] data = new byte[alldata.Length - 128];
                for (int i = 0; i < alldata.Length - 128; i++)
                { data[i] = alldata[i]; }
                for (int i = alldata.Length - 128, j = 0; i < alldata.Length; i++, j++)
                { getencryptedkey[j] = alldata[i]; }
                using (BinaryWriter bw = new BinaryWriter(File.Create(encName)))
                {
                    bw.Write(data);
                    bw.Close();
                }
                #endregion 

                #region key decryption
                StreamReader reader = new StreamReader("PublicPrivateKey.xml");
                string publicprivatekeyxml = reader.ReadToEnd();
                RSA.FromXmlString(publicprivatekeyxml);
                reader.Close();
                byte[] decryptedKey = RSA.Decrypt(getencryptedkey, false);
                pwd = System.Text.ASCIIEncoding.Unicode.GetString(decryptedKey);
                byte[] dk = null;
                byte[] div = null;
                crm.getKeysFromPassword(pwd, out dk, out div);
                cryptoKey = dk;
                cryptoIV = div;
                #endregion

                string ext = Path.GetExtension(encName).ToLower();
                if (ext != ".enc")
                {
                    MessageBox.Show("Please Enter correct File");
                    return;
                }
                string dncName = Path.GetDirectoryName(encName) + "\\" + Path.GetFileNameWithoutExtension(encName);
                dncName = current.Date.Day.ToString() + current.Date.Month.ToString() + current.Date.Year.ToString() + current.TimeOfDay.Duration().Hours.ToString() + current.TimeOfDay.Duration().Minutes.ToString() + current.TimeOfDay.Duration().Seconds.ToString() + ".wmv";
                try
                {
                    if (crm.DecryptData(encName, dncName, cryptoKey, cryptoIV))
                    {
                        FileInfo fi = new FileInfo(encName);
                        FileInfo fi2 = new FileInfo(dncName);
                        if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                        { fi.Attributes &= ~FileAttributes.ReadOnly; }
                        //copy creation and modification time
                        fi2.CreationTime = fi.CreationTime;
                        fi2.LastWriteTime = fi.LastWriteTime;
                        //delete encrypted file
                        File.Delete(encName);
                        MessageBox.Show("File Decrypted");
                    }
                    else
                    {
                        MessageBox.Show("The file can't be decrypted - probably wrong password");
                    }
                }

                catch (CryptographicException ex)
                { MessageBox.Show(ex.Message); }
                catch (IOException ex)
                { MessageBox.Show(ex.Message); }
                catch (UnauthorizedAccessException ex)
                { //i.e. readonly
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message); }
        }

【问题讨论】:

    标签: asp.net video encryption video-streaming


    【解决方案1】:

    要对视频文件进行复制保护,过去最好的方法是对其应用 DRM。这样你就可以限制它应该播放的次数或它应该对用户可用的时间,但这仍然可以通过很多方式来打破。

    您不能对任何视频进行 100% 复制保护。请阅读下面的文章。如果是这样,好莱坞电影将无法通过种子网络免费获得。

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

    【讨论】:

    • 感谢 Aby 发帖,实际上视频是在 usb 中提供的。我要保护视频的(复制保护)不受 USB 的影响。我在互联网上搜索过,但没有找到任何东西。所以我想到了加密和解密视频。说真的这是一个新的任务,我从来没有去过。加密和解密的部分已经完成,但是玩起来很难。所以你说的,我必须做的和做的步骤。
    • @user3119503,您可能会做的阻止临时用户复制的方法是将视频以某种方式“隐藏”在 USB 驱动器中(可能通过设置文件属性或更改文件扩展名或您提到过,对其进行某种加密,并与 USB 驱动器一起使用另一个自动运行 exe,这将重命名/解密文件并通过合适的播放器打开视频......但这根本不是万无一失的。
    • 和我想的一样,我在usb上的exe会解密加密的文件(.enc)。它工作正常我已将文件解密为 (.dnc) .,但我不知道如何在播放器中播放此解密文件。
    • @user3119503 为什么它会解密为 '.dnc' ?尝试将其重命名为 .avi 或 .mp4(这是您的原始扩展名)并尝试播放。
    • 您的话对我有用,将格式更改为原始文件格式。但是解密文件创造了复制文件的机会。我们可以尝试从解密的内存流中播放视频文件吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 2014-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多