Ejemplo n.º 1
0
        //public MemoryStream DecryptedStream;

        // Called if the file has a password.  Reads the password hash from the file
        // and prompts the user to enter a matching password.
        // Returns true if the user enters the correct password.
        private bool PromptUserForPassword()
        {
            var hash = _fileReader.ReadBytes(20);
            var hint = _fileReader.ReadString();

            if (_lastHash != null && hash.SequenceEqual(_lastHash))
            {
                // Either the same file is being loaded again (refreshed),
                // or a different file has the same password.  Either way,
                // don't ask for the same password again.
                return(true);
            }
            else
            {
                PasswordDialog dlg    = new PasswordDialog(hash, hint);
                DialogResult   result = dlg.ShowDialog();

                if (result == DialogResult.OK)
                {
                    _lastHash = hash;
                    Key       = dlg.EncryptionKey;
                    return(true);
                }
                else
                {
                    _lastHash = null;
                    Key       = null;
                    return(false);
                }
            }
        }
Ejemplo n.º 2
0
        // Called if the file has a password.  Reads the password hash from the file
        // and prompts the user to enter a matching password.
        // Returns true if the user enters the correct password.
        private bool PromptUserForPassword()
        {
            int hash = _fileReader.ReadInt32();

            if (hash == _lastHash)
            {
                // Either the same file is being loaded again (refreshed),
                // or a different file has the same password.  Either way,
                // don't ask for the same password again.
                return(true);
            }
            else
            {
                PasswordDialog dlg    = new PasswordDialog(hash);
                DialogResult   result = dlg.ShowDialog();
                if (result == DialogResult.OK)
                {
                    _lastHash = hash;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }