public void EncryptFile(string input, string output,RijndaelManaged alg1)
        {
            FileStream inputStream = new FileStream(input, FileMode.Open, FileAccess.Read);
            FileStream outputStream = new FileStream(output, FileMode.OpenOrCreate, FileAccess.Write);

            SymmetricAlgorithm alg = new RijndaelManaged();
            alg.Key = alg1.Key;
            alg.IV = alg1.IV;

            byte[] data = new byte[inputStream.Length];
            inputStream.Read(data, 0, (int)data.Length);


            alg.Padding = PaddingMode.PKCS7;

            ICryptoTransform encryptor = alg.CreateEncryptor();
            CryptoStream stream = new CryptoStream(outputStream, encryptor, CryptoStreamMode.Write);

            // WRITE THE DATA ENCRYPTING
            stream.Write(data, 0, data.Length);

            // CLOSE SEGMENT
            stream.Close();
            inputStream.Close();
            outputStream.Close();

        }

This is the algorithm which i use for encrypting file, but if try encrypting a huge video file of size 700 mb , it gives out of memory exception.

so can u please tell me how to read just around 25 mb and encrypt that and next read the next 25mb and encrypt it into same file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.