示例#1
0
        public static void EncryptFile(string file, string password)
        {
            byte[] fileByte     = File.ReadAllBytes(file);
            byte[] passwordByte = Encoding.UTF8.GetBytes(password);
            byte[] aesEncrypted = AESClass.AES_Encryption(fileByte, passwordByte);

            // DO NOT DELETE/MOVE THE ORIGINAL FILE
            File.WriteAllBytes(file + ".encrypted", aesEncrypted);
        }
示例#2
0
        public static bool DecryptFile(string file, string password)
        {
            byte[] fileByte     = File.ReadAllBytes(file);
            byte[] passwordByte = Encoding.UTF8.GetBytes(password);
            byte[] aesDecrypted = AESClass.AES_Decrypt(fileByte, passwordByte);
            if (aesDecrypted == null)
            {
                return(false);
            }

            string addedExtension = System.IO.Path.GetExtension(file);
            string originalName   = file.Substring(0, file.Length - addedExtension.Length);

            string originalExtension = System.IO.Path.GetExtension(originalName);
            string newName           = originalName + "++DECRYPTED++" + originalExtension;

            File.WriteAllBytes(newName, aesDecrypted);
            return(true);
        }