public static void DecryptFile(FileInfo file, byte[] key)
        {
            if (file == null || !file.Exists)
            {
                throw new FileNotFoundException();
            }

            var bytes   = File.ReadAllBytes(file.FullName);
            var tmpName = file.FullName + ".tmp";

            try
            {
                using (var fileStream =
                           new FileStream(tmpName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                {
                    var m = WeakSymmetricEncryption.Decrypt(bytes, key, WeakCryptoConfig.SaltSizeBytes);
                    fileStream.Write(m, 0, m.Length);
                }
                File.Delete(file.FullName);
                File.Move(tmpName, tmpName.Replace(".falsecrypt.tmp", ""));
            }
            catch (Exception)
            {
                File.Delete(file.FullName + ".tmp");
                throw;
            }
        }
        public static byte[] DecryptMessage(byte[] encryptedMessage, string password)
        {
            if (encryptedMessage == null || encryptedMessage.Length == 0)
            {
                throw new ArgumentException("Encrypted Message Required!", nameof(encryptedMessage));
            }

            var data = WeakPasswordDerivation.DerivePassword(password);

            return(WeakSymmetricEncryption.Decrypt(encryptedMessage, data.Key, data.Salt.Length));
        }
        public static string DecryptMessage(string encryptedMessage, byte[] key, Encoding encoding)
        {
            if (string.IsNullOrWhiteSpace(encryptedMessage))
            {
                throw new ArgumentException("Encrypted Message Required!", nameof(encryptedMessage));
            }

            var cipherText = Convert.FromBase64String(encryptedMessage);
            var plainText  = WeakSymmetricEncryption.Decrypt(cipherText, key, 0);

            return(plainText == null ? null : Encoding.UTF8.GetString(plainText));
        }
        public static void EncryptFile(FileInfo file, byte[] key, byte[] salt)
        {
            if (file == null || !file.Exists)
            {
                throw new FileNotFoundException();
            }

            var bytes = File.ReadAllBytes(file.FullName);

            using (var fileStream = new FileStream(file.FullName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
            {
                var cipherText = WeakSymmetricEncryption.Encrypt(bytes, key, salt);
                fileStream.Write(cipherText, 0, cipherText.Length);
            }

            file.MoveTo(Path.Combine(file.Directory.FullName, file.Name + ".falsecrypt"));
        }
        public static byte[] EncryptMessage(byte[] secretMessage, string password)
        {
            var data = WeakPasswordDerivation.DerivePassword(password);

            return(WeakSymmetricEncryption.Encrypt(secretMessage, data.Key, data.Salt));
        }
 public static byte[] EncryptMessage(byte[] secretMessage, byte[] key, byte[] nonSecretPayload)
 {
     return(WeakSymmetricEncryption.Encrypt(secretMessage, key, nonSecretPayload));
 }
 public static byte[] EncryptMessage(byte[] secretMessage, byte[] key)
 {
     return(WeakSymmetricEncryption.Encrypt(secretMessage, key, null));
 }