本文整理汇总了C#中KeePassLib.Keys.CompositeKey.GetUserKey方法的典型用法代码示例。如果您正苦于以下问题:C# CompositeKey.GetUserKey方法的具体用法?C# CompositeKey.GetUserKey怎么用?C# CompositeKey.GetUserKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KeePassLib.Keys.CompositeKey
的用法示例。
在下文中一共展示了CompositeKey.GetUserKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetKeySources
public void SetKeySources(IOConnectionInfo iocDb, CompositeKey cmpKey)
{
string strID = GetKeyAssocID(iocDb);
int idx = GetKeyAssocIndex(strID);
if((cmpKey == null) || !m_bRememberKeySources)
{
if(idx >= 0) m_vKeySources.RemoveAt(idx);
return;
}
AceKeyAssoc a = new AceKeyAssoc();
a.DatabasePath = strID;
IUserKey kcpFile = cmpKey.GetUserKey(typeof(KcpKeyFile));
if(kcpFile != null)
{
string strKeyFile = ((KcpKeyFile)kcpFile).Path;
if(!string.IsNullOrEmpty(strKeyFile) && !StrUtil.IsDataUri(strKeyFile))
{
if(!UrlUtil.IsAbsolutePath(strKeyFile))
strKeyFile = UrlUtil.MakeAbsolutePath(WinUtil.GetExecutable(),
strKeyFile);
a.KeyFilePath = strKeyFile;
}
}
IUserKey kcpCustom = cmpKey.GetUserKey(typeof(KcpCustomKey));
if(kcpCustom != null)
a.KeyProvider = ((KcpCustomKey)kcpCustom).Name;
IUserKey kcpUser = cmpKey.GetUserKey(typeof(KcpUserAccount));
a.UserAccount = (kcpUser != null);
bool bAtLeastOne = ((a.KeyFilePath.Length > 0) ||
(a.KeyProvider.Length > 0) || a.UserAccount);
if(bAtLeastOne)
{
if(idx >= 0) m_vKeySources[idx] = a;
else m_vKeySources.Add(a);
}
else if(idx >= 0) m_vKeySources.RemoveAt(idx);
}
示例2: SetDatabaseKey
private static KdbErrorCode SetDatabaseKey(KdbManager mgr, CompositeKey pwKey)
{
KdbErrorCode e;
bool bPassword = pwKey.ContainsType(typeof(KcpPassword));
bool bKeyFile = pwKey.ContainsType(typeof(KcpKeyFile));
string strPassword = (bPassword ? (pwKey.GetUserKey(
typeof(KcpPassword)) as KcpPassword).Password.ReadString() : string.Empty);
string strKeyFile = (bKeyFile ? (pwKey.GetUserKey(
typeof(KcpKeyFile)) as KcpKeyFile).Path : string.Empty);
if(bPassword && bKeyFile)
e = mgr.SetMasterKey(strKeyFile, true, strPassword, IntPtr.Zero, false);
else if(bPassword && !bKeyFile)
e = mgr.SetMasterKey(strPassword, false, null, IntPtr.Zero, false);
else if(!bPassword && bKeyFile)
e = mgr.SetMasterKey(strKeyFile, true, null, IntPtr.Zero, false);
else if(pwKey.ContainsType(typeof(KcpUserAccount)))
throw new Exception(KPRes.KdbWUA);
else throw new Exception(KLRes.InvalidCompositeKey);
return e;
}