Esempio n. 1
0
        public static void Encrypt(string file, CryptCredentials credentials)
        {
            while (IsFileLocked(new FileInfo(file)))
            {
                Thread.Sleep(1000);
            }

            if (File.Exists(file))
            {
                string fileData = File.ReadAllText(file);
                File.Delete(file);
                string fileDataCrypted = Convert.ToBase64String(CryptManager.Encrypt(fileData, credentials.key, credentials.iv));
                File.WriteAllText(file, fileDataCrypted);
            }
        }
Esempio n. 2
0
        public static string Decrypt(string file, CryptCredentials credentials)
        {
            while (IsFileLocked(new FileInfo(file)))
            {
                Thread.Sleep(1000);
            }

            if (File.Exists(file))
            {
                string fileData = File.ReadAllText(file);
                File.Delete(file);
                string fileDataDecrypted = CryptManager.Decrypt(Convert.FromBase64String(fileData), credentials.key, credentials.iv);
                File.WriteAllText(file, fileDataDecrypted);
                return(fileDataDecrypted);
            }
            return(string.Empty);
        }