/// <summary>
        /// Occures when PassEncryptMenuItem option in text menu is cliced or crtl+e keys pressed.
        /// Gets selected text, shows pasword prompt and encrypts text in PassEncryptTag.
        /// </summary>
        protected async override void OnActivated()
        {
            Logger.Info("PassEncryptMenuItem: Encrypting Text...");
            if (Addin.Note.Buffer.HasSelection)
            {
                string   selection = Addin.Note.Buffer.Selection.Trim();
                TextIter start, end;
                Addin.Note.Buffer.GetSelectionBounds(out start, out end);
                if (string.IsNullOrWhiteSpace(selection))
                {
                    return;
                }
                PasswordWindow passwordWindow = new PasswordWindow(true);
                passwordWindow.ShowAll();
                string passPhrase = await passwordWindow.GetPassword();

                if (string.IsNullOrWhiteSpace(passPhrase))
                {
                    return;
                }
                string         encPassword = (new Encrypter()).Encrypt(selection, passPhrase);
                PassEncryptTag encPassTag  = (PassEncryptTag)Addin.Note.TagTable.CreateDynamicTag(PassEncryptTag.TagName);
                encPassTag.SetPassword(encPassword);
                encPassTag.SaveBackupCopy(Addin.Note.FilePath);
                Gtk.TextTag[] tags = { encPassTag };
                Addin.Note.Buffer.DeleteInteractive(ref start, ref end, true);
                Addin.Note.Buffer.InsertWithTags(ref start, Catalog.GetString(" -Encrypted Text- "), tags);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Method used do decrypt password.
        /// Shows new PasswordWindow and asks for decrypting passPhrase, then shows decrypted password on that window.
        /// </summary>
        /// <param name="encPass"> Encrypted password which needs to be decrypted by user entered passPhrase. </param>
        protected async void DecryptPassAsync(string encPass)
        {
            PasswordWindow passwordWindow = new PasswordWindow(false);

            passwordWindow.ShowAll();
            string passPhrase = await passwordWindow.GetPassword();

            if (string.IsNullOrEmpty(passPhrase))
            {
                return;
            }

            string decrypted = (new Encrypter()).Decrypt(encPass, passPhrase);

            passwordWindow.ShowNonEditableText(decrypted);
        }