예제 #1
0
        public static void DecryptFile(string inputFile, string outputFile, string keyIV)
        {
            byte[] array  = new byte[32];
            byte[] array2 = new byte[16];
            AssetStoreUtils.HexStringToByteArray(keyIV, array, 0);
            AssetStoreUtils.HexStringToByteArray(keyIV, array2, 64);
            FileStream fileStream  = File.Open(inputFile, FileMode.Open);
            FileStream fileStream2 = File.Open(outputFile, FileMode.CreateNew);
            AesManaged aesManaged  = new AesManaged();

            aesManaged.Key = array;
            aesManaged.IV  = array2;
            CryptoStream cryptoStream = new CryptoStream(fileStream, aesManaged.CreateDecryptor(aesManaged.Key, aesManaged.IV), CryptoStreamMode.Read);

            try
            {
                byte[] array3 = new byte[40960];
                int    count;
                while ((count = cryptoStream.Read(array3, 0, array3.Length)) > 0)
                {
                    fileStream2.Write(array3, 0, count);
                }
            }
            finally
            {
                cryptoStream.Close();
                fileStream.Close();
                fileStream2.Close();
            }
        }
예제 #2
0
        public static void DecryptFile(string inputFile, string outputFile, string keyIV)
        {
            byte[] array  = new byte[32];
            byte[] array2 = new byte[16];
            AssetStoreUtils.HexStringToByteArray(keyIV, array, 0);
            AssetStoreUtils.HexStringToByteArray(keyIV, array2, 64);
            EditorUtility.DisplayProgressBar("Decrypting", "Decrypting package", 0f);
            FileStream fileStream  = File.Open(inputFile, FileMode.Open);
            FileStream fileStream2 = File.Open(outputFile, FileMode.CreateNew);
            long       length      = fileStream.Length;
            long       num         = 0L;
            AesManaged aesManaged  = new AesManaged();

            aesManaged.Key = array;
            aesManaged.IV  = array2;
            CryptoStream cryptoStream = new CryptoStream(fileStream, aesManaged.CreateDecryptor(aesManaged.Key, aesManaged.IV), CryptoStreamMode.Read);

            try
            {
                byte[] array3 = new byte[40960];
                int    num2;
                while ((num2 = cryptoStream.Read(array3, 0, array3.Length)) > 0)
                {
                    fileStream2.Write(array3, 0, num2);
                    num += (long)num2;
                    if (EditorUtility.DisplayCancelableProgressBar("Decrypting", "Decrypting package", (float)num / (float)length))
                    {
                        throw new Exception("User cancelled decryption");
                    }
                }
            }
            finally
            {
                cryptoStream.Close();
                fileStream.Close();
                fileStream2.Close();
                EditorUtility.ClearProgressBar();
            }
        }