本文整理汇总了C#中PwEntry.GetSshKey方法的典型用法代码示例。如果您正苦于以下问题:C# PwEntry.GetSshKey方法的具体用法?C# PwEntry.GetSshKey怎么用?C# PwEntry.GetSshKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PwEntry
的用法示例。
在下文中一共展示了PwEntry.GetSshKey方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddEntry
public ISshKey AddEntry(PwEntry entry,
ICollection<Agent.KeyConstraint> constraints)
{
var settings = entry.GetKeeAgentSettings();
try {
var key = entry.GetSshKey();
string db_name = "<Unknown database>";
try {
var database = pluginHost.MainWindow.DocumentManager.GetOpenDatabases()
.Where((db) => db.RootGroup.FindEntry(entry.Uuid, true) != null).Single();
db_name = database.Name;
} catch (Exception) {
Debug.Fail("Duplicate UUIDs?");
}
key.Source = string.Format("{0}: {1}", db_name, entry.GetFullPath());
if (agent is PageantClient) {
// Pageant errors if you try to add a key that is already loaded
// so try to remove the key first so that it behaves like other agents
try {
agent.RemoveKey(key);
} catch (Exception) {
// ignore failure
}
} else {
// also, Pageant does not support constraints
if (constraints != null) {
foreach (var constraint in constraints) {
key.AddConstraint(constraint);
}
} else {
if (settings.UseConfirmConstraintWhenAdding) {
key.addConfirmConstraint();
}
if (settings.UseLifetimeConstraintWhenAdding) {
key.addLifetimeConstraint(settings.LifetimeConstraintDuration);
}
}
if (Options.AlwaysConfirm &&
!key.HasConstraint(Agent.KeyConstraintType.SSH_AGENT_CONSTRAIN_CONFIRM))
{
key.addConfirmConstraint();
}
}
agent.AddKey(key);
if (settings.Location.SelectedType == EntrySettings.LocationType.Attachment
&& settings.Location.SaveAttachmentToTempFile)
{
try {
var data = entry.Binaries.Get(settings.Location.AttachmentName).ReadData();
var tempPath = Path.Combine(UrlUtil.GetTempPath(), "KeeAgent");
if (!Directory.Exists(tempPath))
Directory.CreateDirectory(tempPath);
var fileName = Path.Combine(tempPath, settings.Location.AttachmentName);
File.WriteAllBytes(fileName, data);
keyFileMap[key.GetMD5Fingerprint().ToHexString()] = new KeyFileInfo(fileName, true);
} catch (Exception ex) {
Debug.Fail(ex.Message, ex.StackTrace);
}
}
if (settings.Location.SelectedType == EntrySettings.LocationType.File) {
keyFileMap[key.GetMD5Fingerprint().ToHexString()] =
new KeyFileInfo(settings.Location.FileName, false);
}
return key;
} catch (Exception ex) {
var firstLine = string.Format("KeeAgent: Error while loading key from entry '{0}'",
entry.GetFullPath());
if (ex is NoAttachmentException) {
MessageService.ShowWarning(new string[] {
firstLine,
"No attachment specified in KeePass entry"
});
} else if (ex is FileNotFoundException || ex is DirectoryNotFoundException) {
if (!Options.IgnoreMissingExternalKeyFiles) {
MessageService.ShowWarning(new string[] {
firstLine,
"Could not find file",
settings.Location.FileName
});
}
} else if (ex is KeyFormatterException || ex is PpkFormatterException) {
MessageService.ShowWarning(new string[] {
firstLine,
string.Format ("Could not load file {0}",
settings.Location.SelectedType == EntrySettings.LocationType.File
? string.Format("'{0}'", settings.Location.FileName)
: string.Format("from attachment '{0}'", settings.Location.AttachmentName)),
"Possible causes:",
"- Passphrase was entered incorrectly",
"- File is corrupt or has been tampered"
});
} else if (ex is AgentFailureException) {
MessageService.ShowWarning(new string[] {
firstLine,
"Agent Failure",
"Possible causes:",
"- Key is already loaded in agent",
"- Agent is locked"
//.........这里部分代码省略.........