GetPublicKey() public method

Return the first public key in the ring.
public GetPublicKey ( ) : PgpPublicKey
return PgpPublicKey
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
         }
     }
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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));
 }
        /// <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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 10
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)
        {
            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));
        }
Ejemplo n.º 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));
 }
        /// <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);
        }
        /// <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);
        }
Ejemplo n.º 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 ();
		}
Ejemplo n.º 15
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)
		{
			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);
		}