Example #1
0
        //Decrypts a file to be stored on the local computer
        public static bool DecryptFile(string fileKey, byte[] fileData)
        {
            ApprovedFile file;

            //Check if the file is on the white list
            if (Whitelist.TryGetValue(fileKey, out file))
            {
                try
                {
                    //decrypt the file
                    var passwordBytes   = Encoding.UTF8.GetBytes(file.Password.ToUnsecureString());
                    var decryptedFile   = UlteriusAes.DecryptFile(fileData, passwordBytes);
                    var destinationPath = file.DestinationPath;
                    //Write the files data to disk
                    System.IO.File.WriteAllBytes(destinationPath, decryptedFile);
                    //Remove the file from the white list
                    RemoveFile(fileKey);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }
Example #2
0
        public static bool DecryptFile(string fileKey, byte[] fileData)
        {
            ApprovedFile file;

            if (Whitelist.TryGetValue(fileKey, out file))
            {
                try
                {
                    var passwordBytes   = Encoding.UTF8.GetBytes(file.Password);
                    var decryptedFile   = UlteriusAes.DecryptFile(fileData, passwordBytes);
                    var destinationPath = file.DestinationPath;
                    System.IO.File.WriteAllBytes(destinationPath, decryptedFile);
                    RemoveFile(fileKey);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            return(false);
        }