This documentation applies to KeePass 2.x plugins. 2.x plugins are fundamentally
different from 1.x plugins. 2.x plugins cannot be loaded by KeePass 1.x.
This article is intended for KeePass plugin developers. If you are looking
for ready-to-use key providers, see the
Plugins page.
Introduction
For an introduction about what key provider plugins are, see the
KeePass 1.x Key Providers page.
A 2.x key provider plugin derives from the KeePassLib.Keys.KeyProvider class
and registers itself in the key provider pool by using the Add method
of the KeyProviderPool class in the IPluginHost interface
that you get in the Initialize function. Don't forget to unregister your
plugin using Remove when KeePass calls your plugin's Terminate
method.
Sample Source Code
Here's the source code of a very simple key provider plugin for KeePass 2.x. This
code is complete and can be compiled as-is.
using System;
using KeePass.Plugins;
using KeePassLib.Keys;
namespace KeyProviderTest
{
public sealed class KeyProviderTestExt : Plugin
{
private IPluginHost m_host = null;
private SampleKeyProvider m_prov = new SampleKeyProvider();
public override bool Initialize(IPluginHost host)
{
m_host = host;
m_host.KeyProviderPool.Add(m_prov);
return true;
}
public override void Terminate()
{
m_host.KeyProviderPool.Remove(m_prov);
}
}
public sealed class SampleKeyProvider : KeyProvider
{
public override string Name
{
get { return "Sample Key Provider"; }
}
public override byte[] GetKey(KeyProviderQueryContext ctx)
{
// Return a sample key. In a real key provider plugin, the key
// would be retrieved from smart card, USB device, ...
return new byte[]{ 2, 3, 5, 7, 11, 13 };
}
}
}
|