Stream AVI file from memory using IIS / Asp.Net

I have some AVI files on the disk, but they are encrypted. I am wondering if it is possible to decrypt them and transfer them to the browser (using MemoryStreamor something similar) without having to write any files?

I know that Windows Media Services , but I'm using a Vista machine, and Windows Media Services will only be installed on Windows Server 2003 and 2008.

Is there a way to do this without much trouble, or is Media Services / Windows Server the only way? And if there is, would I use something like a custom IHttpHandler(.ashx file)?


Edit:

I decided to use custom IHttpHandler. What basic code will I need to play the video?

+3
source share
1 answer

I would not want to use MemoryStreamfor video. Assuming that you can create CryptoStream(found in the namespace System.Security.Cryptography), the encrypted file AVI, you just have to pump Readfrom it up Writeon Response.OutputStreamto IHttpHandlersomething like: -

 byte[] buffer = new byte[65556];  // adjust the buffer size as yo prefer.
 CryptoStream inStream = YourFunctionToDecryptAVI(aviFilePath);
 int bytesRead = inStream.Read(buffer, 0, 65556); 
 while (bytesRead != 0)
 {
    context.Response.OutputStream.Write(buffer, 0, bytesRead); 
    bytesRead = inStream.Read(buffer, 0, 65556);
    if (!context.Response.IsClientConnected) break;
 }
 Response.Close();  //see edit note.

Make sure you turn off the response buffer and specify the type of content.

Edit

Usually I hate to call closely, it seems draconian. However, while coded encoding should not require this, in the case of streaming video it may be that the client does not like it. Also with large data transfers, closing the connection does not really matter much.

+1
source

Source: https://habr.com/ru/post/1717185/


All Articles