Esempio n. 1
0
 public static CryptCredentials FromPassword(string _password, string _salt, string _iv)
 {
     byte[] _bSalt = Convert.FromBase64String(_salt);
     return(new CryptCredentials()
     {
         key = CryptManager.CreateKey(_password, _bSalt),
         salt = _bSalt,
         iv = Convert.FromBase64String(_iv)
     });
 }
Esempio n. 2
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. 3
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);
        }