Beispiel #1
0
        public void Secure(string password)
        {
            if (!string.IsNullOrEmpty(password) && (password.Length < 1 || password.Length > 256))
            {
                throw new SecurityException("Password length should be between 1 and 256.");
            }

            if (string.IsNullOrEmpty(this.Password))
            {
                if (Changed != null)
                {
                    Changed(this, EventArgs.Empty);
                }

                this.Password = CryptoHelper.GetSHA256HashData(password);
                var dbfiles = Directory.GetFiles(Directory.GetParent(this.Path).FullName).Where(s =>
                                                                                                s.EndsWith(".xod") ||
                                                                                                s.EndsWith(".xtab") ||
                                                                                                s.EndsWith(".xpag"));

                foreach (var file in dbfiles)
                {
                    FileCryptoHelper.EncryptFile(file, file + ".lock", this.Password);
                    File.Delete(file);
                    File.Move(file + ".lock", file);
                }
            }
            else
            {
                throw new SecurityException("The database is already protected with a password, if you want to change it use ChangePassword method.");
            }
        }