﻿namespace Argus.Cryptography
{
    /// <summary>
    /// Methods to encrypt and decrypt files.  Encrypt/Decrypt will work assuming memory is adequate.  These methods
    /// will be updated to use a stream in/out to support large files in the future.
    /// </summary>
    /// <remarks>
    /// TODO:  Stream in/out to support large files instead of reading the entire file into memory.
    /// </remarks>
    public class FileEncryption
    {
        //*********************************************************************************************************************
        //
        //             Class:  FileEncryption
        //      Organization:  http://www.blakepell.com
        //      Initial Date:  06/30/2011
        //      Last Updated:  04/09/2016
        //     Programmer(s):  Blake Pell, blakepell@hotmail.com
        //
        //*********************************************************************************************************************

        /// <summary>
        /// Encrypts a file given a specified key.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="key"></param>
        /// <remarks></remarks>
        public static void Encrypt(string filePath, string key)
        {
            string buf = System.IO.File.ReadAllText(filePath);
            buf = StringEncryption.Encrypt(buf, key);
            System.IO.File.WriteAllText(filePath, buf);
        }

        /// <summary>
        /// Decrypts a file given a specified key.
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="key"></param>
        /// <remarks></remarks>
        public static void Decrypt(string filePath, string key)
        {
            string buf = System.IO.File.ReadAllText(filePath);
            buf = StringEncryption.Decrypt(buf, key);
            System.IO.File.WriteAllText(filePath, buf);
        }

    }

}