Ejemplo n.º 1
0
        public static void DecryptFile(string encryptedFilePath, string decryptedFilePath, byte[] key, byte[] iv, long lOrgFileSize)
        {
            if (File.Exists(decryptedFilePath))
            {
                File.Delete(decryptedFilePath);
            }
            long length = new FileInfo(encryptedFilePath).Length;
            long num1   = (long)(int)(length / (long)Encipher.chunkSize + 1L);
            bool flag   = true;

            try
            {
                for (long index = 0; index < num1; ++index)
                {
                    int    readCount;
                    byte[] bytesFromFile = Encipher.GetBytesFromFile(encryptedFilePath, (long)Encipher.headerSize + index * (long)Encipher.chunkSize, out readCount);
                    if (readCount > 0)
                    {
                        byte[] cipherText = new byte[readCount];
                        Buffer.BlockCopy((Array)bytesFromFile, 0, (Array)cipherText, 0, readCount);
                        byte[] _ByteArray = Encipher.DecryptStringFromBytes(cipherText, key, iv, readCount);
                        flag = Encipher.WriteBytesToFile(decryptedFilePath, _ByteArray);
                        if (!flag)
                        {
                            break;
                        }
                    }
                }
                if (!flag)
                {
                    return;
                }
                long       num2       = length - (long)Encipher.headerSize - lOrgFileSize;
                FileInfo   fileInfo   = new FileInfo(decryptedFilePath);
                FileStream fileStream = fileInfo.Open(FileMode.Open);
                fileStream.SetLength(Math.Max(0L, fileInfo.Length - num2));
                fileStream.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Ejemplo n.º 2
0
        public static void DecryptFile(string encryptedFilePath, string decryptedFilePath, byte[] key, byte[] iv, long lOrgFileSize)
        {
            int num;

            if (File.Exists(decryptedFilePath))
            {
                File.Delete(decryptedFilePath);
            }
            long length = (new FileInfo(encryptedFilePath)).Length;
            long num1   = (long)((int)(length / (long)Encipher.chunkSize + (long)1));
            bool file   = true;

            try
            {
                for (long i = (long)0; i < num1; i = i + (long)1)
                {
                    byte[] bytesFromFile = Encipher.GetBytesFromFile(encryptedFilePath, (long)Encipher.headerSize + i * (long)Encipher.chunkSize, out num);
                    if (num > 0)
                    {
                        byte[] numArray = new byte[num];
                        Buffer.BlockCopy(bytesFromFile, 0, numArray, 0, num);
                        byte[] numArray1 = Encipher.DecryptStringFromBytes(numArray, key, iv, num);
                        file = Encipher.WriteBytesToFile(decryptedFilePath, numArray1);
                        if (!file)
                        {
                            break;
                        }
                    }
                }
                if (file)
                {
                    long       num2       = length - (long)Encipher.headerSize - lOrgFileSize;
                    FileInfo   fileInfo   = new FileInfo(decryptedFilePath);
                    FileStream fileStream = fileInfo.Open(FileMode.Open);
                    fileStream.SetLength(Math.Max((long)0, fileInfo.Length - num2));
                    fileStream.Close();
                }
            }
            catch (Exception exception)
            {
            }
        }