---
title: Encryption and Decryption of Video Files Using C#
description: Encryption and Decryption of Video Files Using C#
---

[![e-Zest logo\_An accion lab company\_Colour](https://blog.e-zest.com/hubfs/images/Logos%20with%20Tagline/Corporate/SVG/e-Zest%20logo_An%20accion%20lab%20company_Colour.svg "e-Zest logo_An accion lab company_Colour")](https://www.e-zest.com/)

- [WORK](https://www.e-zest.com/our-work)
- [SERVICES](https://www.e-zest.com/our-services) 
    - [Product Engineering](https://www.e-zest.com/digital-product-engineering-services)
    - [Enterprise Data Services](https://www.e-zest.com/enterprise-data-services)
    - [Digital Commerce](https://www.e-zest.com/digital-commerce-services)
    - [Digital Operations](https://www.e-zest.com/digital-operations)
    - [Digital Consulting](https://www.e-zest.com/digital-transformation-consulting-services)
    - [Digital Experience Design](https://www.e-zest.com/digital-experience-design)
- [INSIGHTS](https://blog.e-zest.com/)
- [CAREERS](https://www.e-zest.com/careers)
- [ENTERPRISE DATA SERVICES](https://www.e-zest.com/enterprise-data-services)
- [GENERATIVE AI](https://www.e-zest.com/generative-ai)
- [Healthcare](https://healthcare.e-zest.com)
- [Contact Us](https://www.e-zest.com/contact-us)

- ![Elevating Product Engineering with AI and ML](https://blog.e-zest.com/hubfs/Elevating%20Product%20Engineering%20with%20AI%20and%20ML.jpg)

  [BLOGS](https://blog.e-zest.com)
  
  #### Elevating Product Engineering with AI and ML

  As technology evolves and customer choices broaden, there is an increasing ...

  [Read more](https://blog.e-zest.com/elevating-product-engineering-with-ai-and-ml)
- ![e-Zest – An Accion Labs Company gets Recognition as a Contender in the ISG Provider Lens™ Study on Digital Engineering Services 2024](https://blog.e-zest.com/hubfs/e-Zest%20%E2%80%93%20An%20Accion%20Labs%20Company%20-%20Gets%20Recognition%20as%20a%20Contender%20in%20the%20ISG%20Provider%20LensTM%20Study%20on%20Digital%20Engineering%20Services%202024.jpg)

  [NEWS](https://blog.e-zest.com/news)
  
  #### e-Zest – An Accion Labs Company gets Recognition as a Contender in the ISG Provider Lens™ Study on Digital Engineering Services 2024

  We are delighted to announce that e-Zest – An Accion Labs Company has been ...

  [Read more](https://blog.e-zest.com/news/e-zest-an-accion-labs-company-gets-recognition-as-a-contender-in-the-isg-provider-lens-study-on-digital-engineering-services-2024)
- ![e-Zest Solutions supports Digital Pune Mission](https://blog.e-zest.com/hubfs/blog-files/Digital%20Literacy%20Bus%20e-Zest.png)

  [CSR](https://blog.e-zest.com/csr)
  
  #### e-Zest Solutions supports Digital Pune Mission

  **Pune, India:** e-Zest Solutions, a leading digital technology innovation ...

  [Read more](https://blog.e-zest.com/csr/e-zest-solutions-supports-digital-pune-mission)

- [Work](https://www.e-zest.com/our-work)
- [Services](https://www.e-zest.com/our-services)
- [Insights](https://blog.e-zest.com)
- [Careers](https://www.e-zest.com/careers)
- [Enterprise Data](https://www.e-zest.com/enterprise-data-services)
- [Generative AI](https://www.e-zest.com/generative-ai)
- [Innovations](https://www.e-zest.com/innovations)
- [Healthcare](https://healthcare.e-zest.com)
- [About](https://www.e-zest.com/about-us)
- [Contact](https://www.e-zest.com/contact-us)

- [Blog](https://blog.e-zest.com/)
- [News](https://blog.e-zest.com/news)
- [CSR](https://blog.e-zest.com/csr)

- [![Linkedin Icon](https://blog.e-zest.com/hubfs/icons/linkedin_icon_white.svg)](https://www.linkedin.com/company/e-zest-solutions/)
- [![Twitter Icon](https://blog.e-zest.com/hubfs/twitter-logo-silhouette%20(5).svg)](https://twitter.com/ezest)
- [![Facebook Icon](https://blog.e-zest.com/hubfs/facebook-app-logo%20(4).svg)](https://www.facebook.com/61259256638)
- [![Instagram Icon](https://blog.e-zest.com/hubfs/instagram-logo%20(4).svg)](https://www.instagram.com/ezestsolutions/)
- [![Youtube Icon](https://blog.e-zest.com/hubfs/icons/youtube_icon_white.svg)](https://www.youtube.com/user/ezestcorporate)

[![Go to top icon](https://blog.e-zest.com/hubfs/AA%20Assets/top%20button.svg)](https://blog.e-zest.com/encryption-and-decryption-of-video-files-using-c/#top)

Hit enter to search or ESC to close

Insights

e-Zest members share technology ideas to foster digital transformation.

- [Blog](https://blog.e-zest.com)
- [News](https://blog.e-zest.com/news)
- [Podcasts](https://www.e-zest.com/podcasts)
- [Healthcare](https://blog.e-zest.com/healthcare)
- [CSR](https://blog.e-zest.com/csr)
- [Whitepaper](https://blog.e-zest.com/whitepaper)
- [Playbook](https://blog.e-zest.com/playbook)
- [Media Kit](https://www.e-zest.com/media-kit)

# Encryption and Decryption of Video Files Using C#

[swapnil.gade](https://blog.e-zest.com/author/swapnil-gade)  Dec 31, 2013

[C#](https://blog.e-zest.com/topic/c) [Encryption of Video Files](https://blog.e-zest.com/topic/encryption-of-video-files) [Microsoft .Net](https://blog.e-zest.com/topic/microsoft-net-2) [Decryption of Video Files](https://blog.e-zest.com/topic/decryption-of-video-files) [Technology](https://blog.e-zest.com/topic/technology)

- <https://www.linkedin.com/shareArticle?mini=true&url=https://blog.e-zest.com/encryption-and-decryption-of-video-files-using-c/&title=&summary=&source=>
- <https://twitter.com/intent/tweet?source=https://blog.e-zest.com/encryption-and-decryption-of-video-files-using-c/&text=Encryption%20and%20Decryption%20of%20Video%20Files%20Using%20C#>
- <https://www.facebook.com/sharer/sharer.php?u=https://blog.e-zest.com/encryption-and-decryption-of-video-files-using-c/>
- <https://www.instagram.com/ezestsolutions/?u=https://blog.e-zest.com/encryption-and-decryption-of-video-files-using-c/>

Encryption is the process of translating plain text data (plaintext) into something that appears to be random and meaningless (cipher text). Decryption is the process of converting cipher text back to plaintext.

For smaller and simpler files (like Text files) we can use DES algorithm, but for other type of files such as a video, we’ll have to use AES or some other algorithm. For this example we’ll be using AES algorithm. AES is a new cryptographic algorithm that can be used to protect electronic data. Typically, AES is an iterative, symmetric-key block cipher that can use keys of 128, 192, and 256 bits, and encrypts and decrypts data in blocks of 128 bits (16 bytes). Unlike public-key ciphers, which use a pair of keys, symmetric-key ciphers use the same key to encrypt and decrypt data. Encrypted data returned by block ciphers have the same number of bits that the input data had. Iterative ciphers use a loop structure that repeatedly performs permutations and substitutions of the input data. Our aim in this article is to Encrypt/Decrypt Video files.

**Encrypt File Code Snippet:**

```

private const string SKey = "_?73^?dVT3st5har3";
private const string SaltKey = "!2S@LT&KT3st5har3EY";
private const int Iterations = 1042; // Recommendation is >= 1000

public static void EncryptFile(string srcFilename, string destFilename)
{
       var aes = new AesManaged();
       aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
       aes.KeySize = aes.LegalKeySizes[0].MaxSize;
       var salt = GetBytes(SaltKey);
       var key = new Rfc2898DeriveBytes(SKey, salt, Iterations);
       aes.Key = key.GetBytes(aes.KeySize / 8);
       aes.IV = key.GetBytes(aes.BlockSize / 8);
       aes.Mode = CipherMode.CBC;
       ICryptoTransform transform = aes.CreateEncryptor(aes.Key, aes.IV);
       using (var dest = new FileStream(destFilename, FileMode.CreateNew,    FileAccess.Write, FileShare.None))
       {
           using (var cryptoStream = new CryptoStream(destination, transform, CryptoStreamMode.Write))
                {
using (var source = new FileStream(srcFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        source.CopyTo(cryptoStream);
                    }
                }
       }
}
```

**Decrypt File Code Snippet:**

```

public static void DecryptFile(string srcFilename, string destFilename)
{
       var aes = new AesManaged();
       aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
       aes.KeySize = aes.LegalKeySizes[0].MaxSize;
       var salt = GetBytes(SaltKey);
       var key = new Rfc2898DeriveBytes(SKey, salt, Iterations);
       aes.Key = key.GetBytes(aes.KeySize / 8);
       aes.IV = key.GetBytes(aes.BlockSize / 8);
       aes.Mode = CipherMode.CBC;
       ICryptoTransform transform = aes.CreateDecryptor(aes.Key, aes.IV);

using (var dest = new FileStream(destFilename, FileMode.CreateNew, FileAccess.Write, FileShare.None))
       {
using (var cryptoStream = new CryptoStream(dest, transform, CryptoStreamMode.Write))
                {
                    try
                    {
using (var source = new FileStream(srcFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
                           {
                                source.CopyTo(cryptoStream);
                            }
                    }
                    catch (CryptographicException exception)
                    {
                        throw new ApplicationException("Decryption failed.",exception);
                    }
                }
        }
 }
```

This code snippet could be used for other file format as well, but my aim for writing this article is to use this for Video file encryption and it has worked well for .wmv, .mpg.

Please let me know if you face any issues with other file types as well.

- <https://twitter.com/intent/tweet?source=https://blog.e-zest.com/encryption-and-decryption-of-video-files-using-c/&text=Encryption%20and%20Decryption%20of%20Video%20Files%20Using%20C#>
- <https://www.facebook.com/sharer/sharer.php?u=https://blog.e-zest.com/encryption-and-decryption-of-video-files-using-c/>
- <https://www.linkedin.com/shareArticle?mini=true&url=https://blog.e-zest.com/encryption-and-decryption-of-video-files-using-c/&title=&summary=&source=>

### Similar Blog

[![Charts in Excel 2010 Using OOXML & C#](https://blog.e-zest.com/hs-fs/file-3395201584-png/blog-files/chart-xml.png) Charts in Excel 2010 Using OOXML & C# Open Office XML (also known as OOXML or OpenXML) is a XML based file format developed by Microsoft for representing office ... By Vitthal Shinde Dec 10, 2012](https://blog.e-zest.com/charts-in-excel-2010-using-ooxml-c-sharp/)

## Helping Organizations Thrive in the Digital Age

[Contact Us](https://www.e-zest.com/contact-us)

- [About](https://www.e-zest.com/about-us)
- [Services](https://www.e-zest.com/our-services)
- [Work](https://www.e-zest.com/our-work)
- [Insights](https://blog.e-zest.com/)
- [Healthcare](https://healthcare.e-zest.com/)
- [Accion Labs](https://www.accionlabs.com/)

- <https://www.linkedin.com/company/e-zest-solutions/>
- <https://twitter.com/ezest>
- <https://www.facebook.com/eZest/>
- <https://www.instagram.com/ezestsolutions/>
- <https://www.youtube.com/user/ezestcorporate>

- Dallas
- Detroit
- Hannover
- Vienna
- London
- Pune

 © 2025 e-Zest Solutions

- [Privacy Policy](https://www.e-zest.com/privacypolicy)
- [Cookie Policy](https://www.e-zest.com/cookie-policy)

 Contact us

 Contact us

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.