-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClass1.cs
110 lines (90 loc) · 3.24 KB
/
Class1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KeePass.Plugins;
using KeePassLib.Keys;
using CredentialManagement;
using KeePass.Forms;
using KeePass.Plugins;
using KeePass.Resources;
using KeePass.UI;
using KeePassLib.Utility;
using System.Windows.Forms;
Windows.Security;
namespace LensFirstKeepassPlugin
{
public sealed class LensFirstKeepassPluginExt : Plugin
{
private IPluginHost m_host = null;
private LensFirstKeepassPlugin m_prov = new LensFirstKeepassPlugin();
private ToolStripSeparator m_tsSeparator = null;
private ToolStripMenuItem m_tsmiMenuItem = null;
public override bool Initialize(IPluginHost host)
{
m_host = host;
ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;
// Add a separator at the bottom
m_tsSeparator = new ToolStripSeparator();
tsMenu.Add(m_tsSeparator);
// Add menu item 'Do Something'
m_tsmiMenuItem = new ToolStripMenuItem();
m_tsmiMenuItem.Text = "WindowsPasswordStorage";
m_tsmiMenuItem.Click += this.OnMenuDoSomething;
tsMenu.Add(m_tsmiMenuItem);
m_host.KeyProviderPool.Add(m_prov);
return true;
}
public override void Terminate()
{
// Remove all of our menu items
ToolStripItemCollection tsMenu = m_host.MainWindow.ToolsMenu.DropDownItems;
m_tsmiMenuItem.Click -= this.OnMenuDoSomething;
tsMenu.Remove(m_tsmiMenuItem);
tsMenu.Remove(m_tsSeparator);
m_host.KeyProviderPool.Remove(m_prov);
}
private void OnMenuDoSomething(object sender, EventArgs e)
{
// Called when the menu item is clicked
PasswordForm passform = new PasswordForm();
passform.Show();
}
}
public sealed class LensFirstKeepassPlugin : KeyProvider
{
public override string Name
{
get { return "Mendel's Sample Key Provider"; }
}
public override byte[] GetKey(KeyProviderQueryContext ctx)
{
string storedpass = "";
string PasswordName = "KeePassPassword";
try
{
Credential credential = new Credential { Target = PasswordName };
if (credential.Exists())
{
credential.Load();
storedpass = credential.Password;
}
else
{
PasswordForm passform = new PasswordForm();
passform.Show();
}
}
catch (Exception e)
{
Console.Write(e);
}
// Return a sample key. In a real key provider plugin, the key
// would be retrieved from smart card, USB device, ...
//byte[] toBytes = Encoding.ASCII.GetBytes("testpassword");
byte[] toBytes = Encoding.ASCII.GetBytes(storedpass);
return toBytes;
}
}
}