vendredi 27 mai 2016

How to play Encrypted video using web API 2

According my requirement to stream video online i found following link to help me out

HTTP 206 Partial Content In ASP.NET Web API - Video File Streaming

Now over this i m using another Encryption library to encrypt my video file.For some reason small size video work fine but large size video not working or not responding. below is my Decryption code so anyone can suggest me any possible solution.

 private static byte[] AES_Decrypt(byte[] bytesToBeDecrypted)
    {
        string password = "abcd1234";
        byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
        passwordBytes = SHA256.Create().ComputeHash(passwordBytes);

        byte[] decryptedBytes = null;

        // Set your salt here, change it to meet your flavor:
        // The salt bytes must be at least 8 bytes.
        byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

        using (MemoryStream ms = new MemoryStream())
        {
            using (RijndaelManaged AES = new RijndaelManaged())
            {
                AES.Padding = PaddingMode.Zeros;
                AES.KeySize = 256;
                AES.BlockSize = 128;

                var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
                AES.Key = key.GetBytes(AES.KeySize / 8);
                AES.IV = key.GetBytes(AES.BlockSize / 8);

                AES.Mode = CipherMode.CBC;

                using (var cs = new CryptoStream(ms, AES.CreateDecryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);
                    cs.Close();
                }
                decryptedBytes = ms.ToArray();
            }
        }
        return decryptedBytes;
    }




Aucun commentaire:

Enregistrer un commentaire