Click here to Skip to main content
15,884,923 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I encrypt my 'video.mp4' into 'encrypt.mp4' . Now I should decrypt my file and save decrypt file to memory at the start of my application. and play them using DirectX in C#.

How to play encrypted video file using DirectX and memoryStream? I dont want to save my video to hard drive (temp folder or another folder) I want to play directly from memory ...

What I have tried:

this code is encrypt and decrypt code :
private void EncryptFile(string inputFile, string outputFile)
   {


       try
       {
           string password = @"myKey123"; // Your Key Here
           UnicodeEncoding UE = new UnicodeEncoding();
           byte[] key = UE.GetBytes(password);


           string cryptFile = outputFile;
           FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);


           RijndaelManaged RMCrypto = new RijndaelManaged();


           CryptoStream cs = new CryptoStream(fsCrypt,
               RMCrypto.CreateEncryptor(key, key),
               CryptoStreamMode.Write);


           FileStream fsIn = new FileStream(inputFile, FileMode.Open);


           int data;
           while ((data = fsIn.ReadByte()) != -1)
               cs.WriteByte((byte)data);




           fsIn.Close();
           cs.Close();
           fsCrypt.Close();
       }
       catch
       {
           MessageBox.Show("Encryption failed!", "Error");
       }
   }


   private void DecryptFile(string inputFile, string outputFile)
   {


       {
           string password = @"myKey123"; // Your Key Here


           UnicodeEncoding UE = new UnicodeEncoding();
           byte[] key = UE.GetBytes(password);


           FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);


           RijndaelManaged RMCrypto = new RijndaelManaged();


           CryptoStream cs = new CryptoStream(fsCrypt,
               RMCrypto.CreateDecryptor(key, key),
               CryptoStreamMode.Read);


           FileStream fsOut = new FileStream(outputFile, FileMode.Create);


           int data;
           while ((data = cs.ReadByte()) != -1)
               fsOut.WriteByte((byte)data);


           fsOut.Close();
           cs.Close();
           fsCrypt.Close();


       }
   }
Posted
Updated 17-Nov-21 17:20pm
Comments
Richard MacCutchan 12-Aug-19 4:34am    
Why are you encrypting it? Just play the original file.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900