本文整理汇总了C#中Org.BouncyCastle.Bcpg.OpenPgp.PgpSecretKey.ExtractPrivateKey方法的典型用法代码示例。如果您正苦于以下问题:C# PgpSecretKey.ExtractPrivateKey方法的具体用法?C# PgpSecretKey.ExtractPrivateKey怎么用?C# PgpSecretKey.ExtractPrivateKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Org.BouncyCastle.Bcpg.OpenPgp.PgpSecretKey
的用法示例。
在下文中一共展示了PgpSecretKey.ExtractPrivateKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetPrivateKey
/// <summary>
/// Gets the private key from the specified secret key.
/// </summary>
/// <returns>The private key.</returns>
/// <param name="key">The secret key.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="key"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The user chose to cancel the password prompt.
/// </exception>
/// <exception cref="System.UnauthorizedAccessException">
/// 3 bad attempts were made to unlock the secret key.
/// </exception>
protected PgpPrivateKey GetPrivateKey(PgpSecretKey key)
{
int attempts = 0;
string password;
if (key == null)
throw new ArgumentNullException ("key");
do {
if ((password = GetPasswordForKey (key)) == null)
throw new OperationCanceledException ();
try {
return key.ExtractPrivateKey (password.ToCharArray ());
} catch (Exception ex) {
Debug.WriteLine ("Failed to extract secret key: {0}", ex);
}
attempts++;
} while (attempts < 3);
throw new UnauthorizedAccessException ();
}
示例2: GetPrivateKey
/// <summary>
/// Gets the private key from the specified secret key.
/// </summary>
/// <remarks>
/// Gets the private key from the specified secret key.
/// </remarks>
/// <returns>The private key.</returns>
/// <param name="key">The secret key.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="key"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The user chose to cancel the password prompt.
/// </exception>
/// <exception cref="System.UnauthorizedAccessException">
/// 3 bad attempts were made to unlock the secret key.
/// </exception>
protected PgpPrivateKey GetPrivateKey (PgpSecretKey key)
{
int attempts = 0;
string password;
if (key == null)
throw new ArgumentNullException ("key");
do {
if ((password = GetPasswordForKey (key)) == null)
throw new OperationCanceledException ();
try {
var privateKey = key.ExtractPrivateKey (password.ToCharArray ());
// Note: the private key will be null if the private key is empty.
if (privateKey == null)
break;
return privateKey;
} catch (Exception ex) {
#if DEBUG
Debug.WriteLine (string.Format ("Failed to extract secret key: {0}", ex));
#endif
}
attempts++;
} while (attempts < 3);
throw new UnauthorizedAccessException ();
}
示例3: PasswordCallback
char[] PasswordCallback(PgpSecretKey masterKey, PgpSecretKey key)
{
if (PassphraseCache.ContainsKey(key.PublicKey.KeyId))
return PassphraseCache[key.KeyId];
// Loop until correct password or user selects cancel
do
{
var passphraseDialog = new FormPassphrase(masterKey, key);
var result = passphraseDialog.ShowDialog();
if (result == DialogResult.Cancel)
return null;
var pass = passphraseDialog.textBoxPassphrase.Text.ToCharArray();
try
{
key.ExtractPrivateKey(pass);
PassphraseCache[key.PublicKey.KeyId] = pass;
_lastPasswordLookupKey = key.PublicKey.KeyId;
return pass;
}
catch (Exception)
{
}
}
while (true);
}