GetPublicKey() public method

Return the first public key in the ring.
public GetPublicKey ( ) : PgpPublicKey
return PgpPublicKey
コード例 #1
14
        /// <summary>
        /// Replace the public key set on the secret ring with the corresponding key off the public ring.
        /// </summary>
        /// <param name="secretRing">Secret ring to be changed.</param>
        /// <param name="publicRing">Public ring containing the new public key set.</param>
        public static PgpSecretKeyRing ReplacePublicKeys(
            PgpSecretKeyRing	secretRing,
            PgpPublicKeyRing	publicRing)
        {
            IList newList = Platform.CreateArrayList(secretRing.keys.Count);

            foreach (PgpSecretKey sk in secretRing.keys)
            {
                PgpPublicKey pk = publicRing.GetPublicKey(sk.KeyId);

                newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
            }

            return new PgpSecretKeyRing(newList);
        }
コード例 #2
0
 public PgpPublicKeyRingBundle(global::System.Collections.IEnumerable e)
 {
     pubRings = Platform.CreateHashtable();
     order    = Platform.CreateArrayList();
     global::System.Collections.IEnumerator enumerator = e.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             object           current          = enumerator.get_Current();
             PgpPublicKeyRing pgpPublicKeyRing = current as PgpPublicKeyRing;
             if (pgpPublicKeyRing == null)
             {
                 throw new PgpException(Platform.GetTypeName(current) + " found where PgpPublicKeyRing expected");
             }
             long keyId = pgpPublicKeyRing.GetPublicKey().KeyId;
             pubRings.Add((object)keyId, (object)pgpPublicKeyRing);
             order.Add((object)keyId);
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
 }
コード例 #3
0
 public PgpPublicKeyRing GetPublicKeyRing(long keyId)
 {
     if (pubRings.Contains((object)keyId))
     {
         return((PgpPublicKeyRing)pubRings.get_Item((object)keyId));
     }
     global::System.Collections.IEnumerator enumerator = GetKeyRings().GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             PgpPublicKeyRing pgpPublicKeyRing = (PgpPublicKeyRing)enumerator.get_Current();
             PgpPublicKey     publicKey        = pgpPublicKeyRing.GetPublicKey(keyId);
             if (publicKey != null)
             {
                 return(pgpPublicKeyRing);
             }
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(null);
 }
コード例 #4
0
 public global::System.Collections.IEnumerable GetKeyRings(string userId, bool matchPartial, bool ignoreCase)
 {
     global::System.Collections.IList list = Platform.CreateArrayList();
     if (ignoreCase)
     {
         userId = Platform.ToUpperInvariant(userId);
     }
     global::System.Collections.IEnumerator enumerator = GetKeyRings().GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             PgpPublicKeyRing pgpPublicKeyRing = (PgpPublicKeyRing)enumerator.get_Current();
             {
                 global::System.Collections.IEnumerator enumerator2 = pgpPublicKeyRing.GetPublicKey().GetUserIds().GetEnumerator();
                 try
                 {
                     while (enumerator2.MoveNext())
                     {
                         string text  = (string)enumerator2.get_Current();
                         string text2 = text;
                         if (ignoreCase)
                         {
                             text2 = Platform.ToUpperInvariant(text2);
                         }
                         if (matchPartial)
                         {
                             if (Platform.IndexOf(text2, userId) > -1)
                             {
                                 list.Add((object)pgpPublicKeyRing);
                             }
                         }
                         else if (text2.Equals(userId))
                         {
                             list.Add((object)pgpPublicKeyRing);
                         }
                     }
                 }
                 finally
                 {
                     global::System.IDisposable disposable2 = enumerator2 as global::System.IDisposable;
                     if (disposable2 != null)
                     {
                         disposable2.Dispose();
                     }
                 }
             }
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(new EnumerableProxy((global::System.Collections.IEnumerable)list));
 }
コード例 #5
0
        /// <summary>
        /// Replace the public key set on the secret ring with the corresponding key off the public ring.
        /// </summary>
        /// <param name="secretRing">Secret ring to be changed.</param>
        /// <param name="publicRing">Public ring containing the new public key set.</param>
        public static PgpSecretKeyRing ReplacePublicKeys(PgpSecretKeyRing secretRing, PgpPublicKeyRing publicRing)
        {
            var newList = Platform.CreateArrayList(secretRing.SecretKeyCount);

            foreach (PgpSecretKey sk in secretRing.GetSecretKeys())
            {
                var pk = publicRing.GetPublicKey(sk.KeyId);
                newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
            }

            return(new PgpSecretKeyRing(newList));
        }
コード例 #6
0
        public static PgpPublicKeyRingBundle RemovePublicKeyRing(PgpPublicKeyRingBundle bundle, PgpPublicKeyRing publicKeyRing)
        {
            //IL_0024: Unknown result type (might be due to invalid IL or missing references)
            long keyId = publicKeyRing.GetPublicKey().KeyId;

            if (!bundle.pubRings.Contains((object)keyId))
            {
                throw new ArgumentException("Bundle does not contain a key with a keyId for the passed in ring.");
            }
            IDictionary val = Platform.CreateHashtable(bundle.pubRings);

            global::System.Collections.IList list = Platform.CreateArrayList((global::System.Collections.ICollection)bundle.order);
            val.Remove((object)keyId);
            list.Remove((object)keyId);
            return(new PgpPublicKeyRingBundle(val, list));
        }
コード例 #7
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle with
        /// the passed in public key ring removed.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be removed from.</param>
        /// <param name="publicKeyRing">The key ring to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> not containing the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is not present.</exception>
        public static PgpPublicKeyRingBundle RemovePublicKeyRing(
            PgpPublicKeyRingBundle bundle,
            PgpPublicKeyRing publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (!bundle.pubRings.Contains(key))
            {
                throw new ArgumentException("Bundle does not contain a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = Platform.CreateHashtable(bundle.pubRings);
            IList       newOrder    = Platform.CreateArrayList(bundle.order);

            newPubRings.Remove(key);
            newOrder.Remove(key);

            return(new PgpPublicKeyRingBundle(newPubRings, newOrder));
        }
コード例 #8
0
        public PgpPublicKeyRingBundle(
            IEnumerable e)
        {
            this.pubRings = Platform.CreateHashtable();
            this.order    = Platform.CreateArrayList();

            foreach (object obj in e)
            {
                PgpPublicKeyRing pgpPub = obj as PgpPublicKeyRing;

                if (pgpPub == null)
                {
                    throw new PgpException(obj.GetType().FullName + " found where PgpPublicKeyRing expected");
                }

                long key = pgpPub.GetPublicKey().KeyId;
                pubRings.Add(key, pgpPub);
                order.Add(key);
            }
        }
コード例 #9
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle and
        /// the passed in public key ring.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be added to.</param>
        /// <param name="publicKeyRing">The key ring to be added.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> merging the current one with the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is already present.</exception>
        public static PgpPublicKeyRingBundle AddPublicKeyRing(
            PgpPublicKeyRingBundle bundle,
            PgpPublicKeyRing publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (bundle.pubRings.Contains(key))
            {
                throw new ArgumentException("Bundle already contains a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = new Hashtable(bundle.pubRings);
            ArrayList   newOrder    = new ArrayList(bundle.order);

            newPubRings[key] = publicKeyRing;

            newOrder.Add(key);

            return(new PgpPublicKeyRingBundle(newPubRings, newOrder));
        }
コード例 #10
0
ファイル: PgpSecretKeyRing.cs プロジェクト: DarkMoon4CN/CLT
        /// <summary>
        /// Replace the public key set on the secret ring with the corresponding key off the public ring.
        /// </summary>
        /// <param name="secretRing">Secret ring to be changed.</param>
        /// <param name="publicRing">Public ring containing the new public key set.</param>
        public static PgpSecretKeyRing ReplacePublicKeys(
            PgpSecretKeyRing secretRing,
            PgpPublicKeyRing publicRing)
        {
            IList newList = Platform.CreateArrayList(secretRing.keys.Count);

            foreach (PgpSecretKey sk in secretRing.keys)
            {
                PgpPublicKey pk = null;
                try
                {
                    pk = publicRing.GetPublicKey(sk.KeyId);
                }
                catch (PgpException e)
                {
                    throw new InvalidOperationException(e.Message, e);
                }

                newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
            }

            return(new PgpSecretKeyRing(newList));
        }
コード例 #11
0
 public static PgpSecretKeyRing ReplacePublicKeys(PgpSecretKeyRing secretRing, PgpPublicKeyRing publicRing)
 {
     global::System.Collections.IList       list       = Platform.CreateArrayList(((global::System.Collections.ICollection)secretRing.keys).get_Count());
     global::System.Collections.IEnumerator enumerator = ((global::System.Collections.IEnumerable)secretRing.keys).GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             PgpSecretKey pgpSecretKey = (PgpSecretKey)enumerator.get_Current();
             PgpPublicKey publicKey    = publicRing.GetPublicKey(pgpSecretKey.KeyId);
             list.Add((object)PgpSecretKey.ReplacePublicKey(pgpSecretKey, publicKey));
         }
     }
     finally
     {
         global::System.IDisposable disposable = enumerator as global::System.IDisposable;
         if (disposable != null)
         {
             disposable.Dispose();
         }
     }
     return(new PgpSecretKeyRing(list));
 }
コード例 #12
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle and
        /// the passed in public key ring.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be added to.</param>
        /// <param name="publicKeyRing">The key ring to be added.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> merging the current one with the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is already present.</exception>
        public static PgpPublicKeyRingBundle AddPublicKeyRing(
            PgpPublicKeyRingBundle  bundle,
            PgpPublicKeyRing        publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (bundle.pubRings.Contains(key))
            {
                throw new ArgumentException("Bundle already contains a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = Platform.CreateHashtable(bundle.pubRings);
            IList newOrder = Platform.CreateArrayList(bundle.order);

            newPubRings[key] = publicKeyRing;

            newOrder.Add(key);

            return new PgpPublicKeyRingBundle(newPubRings, newOrder);
        }
コード例 #13
0
        /// <summary>
        /// Return a new bundle containing the contents of the passed in bundle with
        /// the passed in public key ring removed.
        /// </summary>
        /// <param name="bundle">The <c>PgpPublicKeyRingBundle</c> the key ring is to be removed from.</param>
        /// <param name="publicKeyRing">The key ring to be removed.</param>
        /// <returns>A new <c>PgpPublicKeyRingBundle</c> not containing the passed in key ring.</returns>
        /// <exception cref="ArgumentException">If the keyId for the passed in key ring is not present.</exception>
        public static PgpPublicKeyRingBundle RemovePublicKeyRing(
            PgpPublicKeyRingBundle	bundle,
            PgpPublicKeyRing		publicKeyRing)
        {
            long key = publicKeyRing.GetPublicKey().KeyId;

            if (!bundle.pubRings.Contains(key))
            {
                throw new ArgumentException("Bundle does not contain a key with a keyId for the passed in ring.");
            }

            IDictionary newPubRings = new Hashtable(bundle.pubRings);
            ArrayList newOrder = new ArrayList(bundle.order);

            newPubRings.Remove(key);
            newOrder.Remove(key);

            return new PgpPublicKeyRingBundle(newPubRings, newOrder);
        }
コード例 #14
0
		/// <summary>
		/// Imports a public pgp keyring.
		/// </summary>
		/// <remarks>
		/// Imports a public pgp keyring.
		/// </remarks>
		/// <param name="keyring">The pgp keyring.</param>
		/// <exception cref="System.ArgumentNullException">
		/// <paramref name="keyring"/> is <c>null</c>.
		/// </exception>
		public void Import (PgpPublicKeyRing keyring)
		{
			if (keyring == null)
				throw new ArgumentNullException (nameof (keyring));

			if (PublicKeyRingBundle.Contains (keyring.GetPublicKey ().KeyId))
				return;

			PublicKeyRingBundle = PgpPublicKeyRingBundle.AddPublicKeyRing (PublicKeyRingBundle, keyring);
			SavePublicKeyRingBundle ();
		}
コード例 #15
0
ファイル: PgpSecretKeyRing.cs プロジェクト: pusp/o2platform
		/// <summary>
		/// Replace the public key set on the secret ring with the corresponding key off the public ring.
		/// </summary>
		/// <param name="secretRing">Secret ring to be changed.</param>
		/// <param name="publicRing">Public ring containing the new public key set.</param>
		public static PgpSecretKeyRing ReplacePublicKeys(
			PgpSecretKeyRing	secretRing,
			PgpPublicKeyRing	publicRing)
		{
			IList newList = new ArrayList(secretRing.keys.Count);

			foreach (PgpSecretKey sk in secretRing.keys)
			{
				PgpPublicKey pk = null;
				try
				{
					pk = publicRing.GetPublicKey(sk.KeyId);
				}
				catch (PgpException e)
				{
					throw new InvalidOperationException(e.Message, e);
				}

				newList.Add(PgpSecretKey.ReplacePublicKey(sk, pk));
			}

			return new PgpSecretKeyRing(newList);
		}