public override byte[] GetKey(KeyProviderQueryContext ctx)
        {
            if (ctx.CreatingNewKey)
            {
                MessageService.ShowWarning("Can't use QuickUnlock to create new keys.");

                return(null);
            }

            QuickUnlockData data;

            if (TryGetCachedKey(ctx.DatabasePath, out data) == false ||
                data.IsValid() == false)
            {
                MessageService.ShowWarning("QuickUnlock is not available for this database.");

                return(null);
            }

            using (QuickUnlockPromptForm quof = new QuickUnlockPromptForm())
            {
                if (quof.ShowDialog() != DialogResult.OK)
                {
                    return(null);
                }

                var pb   = data.UnlockKey.ReadUtf8();
                var same = MemUtil.ArraysEqual(pb, StrUtil.Utf8.GetBytes(quof.QuickUnlockKey));
                MemUtil.ZeroByteArray(pb);

                if (same == false)
                {
                    //remove the cache entry
                    RemoveCachedKey(ctx.DatabasePath);

                    //return dummy password to let KeePass fail while loading the database
                    return(new byte[] { 0 });
                }

                return(data.ComposedKey.ReadData());
            }
        }
        public override byte[] GetKey(KeyProviderQueryContext ctx)
        {
            if (ctx.CreatingNewKey)
            {
                MessageService.ShowWarning("Can't use QuickUnlock to create new keys.");

                return(null);
            }

            QuickUnlockData data;

            if (TryGetCachedKey(ctx.DatabasePath, out data) == false ||
                data.IsValid() == false)
            {
                MessageService.ShowWarning("QuickUnlock is not available for this database.");

                return(null);
            }

            using (var quof = new QuickUnlockPromptForm(ctx.IsOnSecureDesktop))
            {
                if (quof.ShowDialog() != DialogResult.OK)
                {
                    return(null);
                }

                ProtectedBinary result;

                var pinBytes = quof.QuickUnlockKey;
                using (var cipher = CreateCipher(pinBytes, data.Nonce))
                {
                    RemoveCachedKey(ctx.DatabasePath);

                    result = data.ComposedKey.Decrypt(cipher);
                }
                MemUtil.ZeroByteArray(pinBytes);

                return(result.ReadData());
            }
        }