当前位置: 首页>>代码示例>>C#>>正文


C# PgpSecretKey.ExtractPrivateKey方法代码示例

本文整理汇总了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 ();
        }
开发者ID:vdaron,项目名称:MimeKit,代码行数:37,代码来源:OpenPgpContext.cs

示例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 ();
		}
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:48,代码来源:OpenPgpContext.cs

示例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);
		}
开发者ID:ALange,项目名称:OutlookPrivacyPlugin,代码行数:29,代码来源:OutlookPrivacyPlugin.cs


注:本文中的Org.BouncyCastle.Bcpg.OpenPgp.PgpSecretKey.ExtractPrivateKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。