示例#1
0
        public static void PasteEntriesFromClipboard(PwDatabase pwDatabase, PwGroup pgStorage)
        {
            if (Clipboard.ContainsData(ClipFormatEntries) == false)
            {
                return;
            }

            byte[] pbEnc = (byte[])Clipboard.GetData(ClipFormatEntries);

            byte[]       pbPlain = ProtectedData.Unprotect(pbEnc, AdditionalEntropy, DataProtectionScope.CurrentUser);
            MemoryStream ms      = new MemoryStream(pbPlain, false);
            GZipStream   gz      = new GZipStream(ms, CompressionMode.Decompress);

            List <PwEntry> vEntries = Kdb4File.ReadEntries(pwDatabase, gz);

            // Adjust protection settings and add entries
            foreach (PwEntry pe in vEntries)
            {
                ProtectedString ps = pe.Strings.Get(PwDefs.TitleField);
                if (ps != null)
                {
                    ps.EnableProtection(pwDatabase.MemoryProtection.ProtectTitle);
                }

                ps = pe.Strings.Get(PwDefs.UserNameField);
                if (ps != null)
                {
                    ps.EnableProtection(pwDatabase.MemoryProtection.ProtectUserName);
                }

                ps = pe.Strings.Get(PwDefs.PasswordField);
                if (ps != null)
                {
                    ps.EnableProtection(pwDatabase.MemoryProtection.ProtectPassword);
                }

                ps = pe.Strings.Get(PwDefs.UrlField);
                if (ps != null)
                {
                    ps.EnableProtection(pwDatabase.MemoryProtection.ProtectUrl);
                }

                ps = pe.Strings.Get(PwDefs.NotesField);
                if (ps != null)
                {
                    ps.EnableProtection(pwDatabase.MemoryProtection.ProtectNotes);
                }

                pgStorage.AddEntry(pe, true, true);
            }

            gz.Close(); ms.Close();
        }
示例#2
0
        private static void PasteEntriesFromClipboardPriv(PwDatabase pwDatabase,
                                                          PwGroup pgStorage)
        {
            if (!Clipboard.ContainsData(ClipFormatEntries))
            {
                return;
            }

            byte[] pbEnc = ClipboardUtil.GetEncodedData(ClipFormatEntries, IntPtr.Zero);
            if (pbEnc == null)
            {
                Debug.Assert(false); return;
            }

            byte[] pbPlain;
            if (WinUtil.IsWindows9x)
            {
                pbPlain = pbEnc;
            }
            else
            {
                pbPlain = ProtectedData.Unprotect(pbEnc, AdditionalEntropy,
                                                  DataProtectionScope.CurrentUser);
            }

            MemoryStream ms = new MemoryStream(pbPlain, false);
            GZipStream   gz = new GZipStream(ms, CompressionMode.Decompress);

            List <PwEntry> vEntries = Kdb4File.ReadEntries(gz);

            // Adjust protection settings and add entries
            foreach (PwEntry pe in vEntries)
            {
                pe.Strings.EnableProtection(PwDefs.TitleField,
                                            pwDatabase.MemoryProtection.ProtectTitle);
                pe.Strings.EnableProtection(PwDefs.UserNameField,
                                            pwDatabase.MemoryProtection.ProtectUserName);
                pe.Strings.EnableProtection(PwDefs.PasswordField,
                                            pwDatabase.MemoryProtection.ProtectPassword);
                pe.Strings.EnableProtection(PwDefs.UrlField,
                                            pwDatabase.MemoryProtection.ProtectUrl);
                pe.Strings.EnableProtection(PwDefs.NotesField,
                                            pwDatabase.MemoryProtection.ProtectNotes);

                pgStorage.AddEntry(pe, true, true);
            }

            gz.Close(); ms.Close();
        }