/// <summary>
        /// Finds a local or remote key given its fingerprint
        /// </summary>
        /// <param name="fingerprint">fingerprint</param>
        /// <returns>a public key</returns>
        public TransportablePublicKey FindPublicKey(string fingerprint)
        {
            IEnumerator ieKeys = this.PublicKeys.GetEnumerator();

            while (ieKeys.MoveNext())
            {
                if (!(ieKeys.Current is TransportablePublicKey))
                {
                    continue;
                }
                TransportablePublicKey key = ((TransportablePublicKey)ieKeys.Current);
                if (key.PrimaryKey.Fingerprint.ToString() == fingerprint)
                {
                    return(key);
                }
            }

            ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();
            string remoteKey           = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer, SharpPrivacyLibrary.LdapPort, "pgpkey", "(pgpsignerid=" + fingerprint + ")");

            if (remoteKey != null)
            {
                ArmorTypes atType = new ArmorTypes();
                string     strKey = Armor.RemoveArmor(remoteKey, ref atType, ref remoteKey);
                if (strKey.Length > 0)
                {
                    TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                    AddPublicKey(tpkKey);
                    return(tpkKey);
                }
            }

            return(null);
        }
        /// <summary>
        /// Finds a remote public key radix64 encoded and server stored
        /// </summary>
        /// <param name="keyID">the keyid of the key as hexadecimal code</param>
        /// <returns>a public key radix64 encoded and PGP armored</returns>
        public string FindRemotePublicKeyByKeyID(string keyID)
        {
            string key = null;

            ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();
            key = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer, SharpPrivacyLibrary.LdapPort, "pgpkey", "(pgpkeyid=" + keyID + ")");
            if (key.Length > 0)
            {
                return(key);
            }
            return(null);
        }
        /// <summary>
        /// Find a remote list of keys which contains the result of the query done using userID as argument.
        /// </summary>
        /// <param name="userID">User ID contained in the keys to list</param>
        /// <returns>a list of keys</returns>
        public ArrayList FindRemotePublicKeysByUserID(string userID)
        {
            ArrayList pkList = new ArrayList();

            ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();
            byte result = kf.MyLDAPSearchByID(SharpPrivacyLibrary.LdapKeyServer, SharpPrivacyLibrary.LdapPort, "pgpkeyid", "(pgpuserid=*" + userID + "*)");

            if (result == 1)
            {
                string[] keys = kf.getKeys();
                pkList = new ArrayList(keys);
            }
            return(pkList);
        }
        /// <summary>
        /// Finds a Key given a keyid. Performs a remote LDAP search if specified.
        /// </summary>
        /// <param name="lKeyID">Key to find</param>
        /// <param name="remote">LDAP search</param>
        /// <returns>a key</returns>
        public TransportablePublicKey Find(ulong lKeyID, bool remote)
        {
            IEnumerator ieKeys = alPublicKeys.GetEnumerator();

            while (ieKeys.MoveNext())
            {
                TransportablePublicKey tpkKey = (TransportablePublicKey)ieKeys.Current;
                if (tpkKey.PrimaryKey.KeyID == lKeyID)
                {
                    return(tpkKey);
                }
                IEnumerator ieSubkeys = tpkKey.SubKeys.GetEnumerator();
                while (ieSubkeys.MoveNext())
                {
                    CertifiedPublicSubkey cpsSubkey = (CertifiedPublicSubkey)ieSubkeys.Current;
                    if (cpsSubkey.Subkey.KeyID == lKeyID)
                    {
                        return(tpkKey);
                    }
                }
            }

            if (remote)
            {
                ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();

                string key = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer, SharpPrivacyLibrary.LdapPort, "pgpkey", "(pgpsignerid=" + lKeyID.ToString("X") + ")");
                if (key != null)
                {
                    ArmorTypes atType = new ArmorTypes();
                    string     strKey = Armor.RemoveArmor(key, ref atType, ref key);
                    if (strKey.Length > 0)
                    {
                        TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                        AddPublicKey(tpkKey);
                        return(tpkKey);
                    }
                }
            }
            return(null);
        }
 /// <summary>
 /// Find a remote list of keys which contains the result of the query done using userID as argument.
 /// </summary>
 /// <param name="userID">User ID contained in the keys to list</param>
 /// <returns>a list of keys</returns>
 public ArrayList FindRemotePublicKeysByUserID(string userID)
 {
     ArrayList pkList = new ArrayList();
     ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();
     byte result = kf.MyLDAPSearchByID(SharpPrivacyLibrary.LdapKeyServer,SharpPrivacyLibrary.LdapPort,"pgpkeyid","(pgpuserid=*"+userID+"*)");
     if(result == 1) {
         string[] keys = kf.getKeys();
         pkList = new ArrayList(keys);
     }
     return pkList;
 }
 /// <summary>
 /// Finds a remote public key radix64 encoded and server stored
 /// </summary>
 /// <param name="keyID">the keyid of the key as hexadecimal code</param>
 /// <returns>a public key radix64 encoded and PGP armored</returns>
 public string FindRemotePublicKeyByKeyID(string keyID)
 {
     string key = null;
     ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();
     key = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer,SharpPrivacyLibrary.LdapPort,"pgpkey","(pgpkeyid="+keyID+")");
     if(key.Length > 0) {
         return key;
     }
     return null;
 }
        /// <summary>
        /// Finds a local or remote key given its fingerprint
        /// </summary>
        /// <param name="fingerprint">fingerprint</param>
        /// <returns>a public key</returns>
        public TransportablePublicKey FindPublicKey(string fingerprint)
        {
            IEnumerator ieKeys = this.PublicKeys.GetEnumerator();
            while (ieKeys.MoveNext()) {
                if (!(ieKeys.Current is TransportablePublicKey)) {
                    continue;
                }
                TransportablePublicKey key = ((TransportablePublicKey)ieKeys.Current);
                if(key.PrimaryKey.Fingerprint.ToString() == fingerprint) {
                    return key;
                }
            }

            ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();
            string remoteKey = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer,SharpPrivacyLibrary.LdapPort,"pgpkey","(pgpsignerid="+fingerprint+")");
            if (remoteKey != null) {
                ArmorTypes atType = new ArmorTypes();
                string strKey = Armor.RemoveArmor(remoteKey, ref atType, ref remoteKey);
                if (strKey.Length > 0) {
                    TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                    AddPublicKey(tpkKey);
                    return tpkKey;
                }
            }

            return null;
        }
        /// <summary>
        /// Finds a Key given a keyid. Performs a remote LDAP search if specified.
        /// </summary>
        /// <param name="lKeyID">Key to find</param>
        /// <param name="remote">LDAP search</param>
        /// <returns>a key</returns>
        public TransportablePublicKey Find(ulong lKeyID, bool remote)
        {
            IEnumerator ieKeys = alPublicKeys.GetEnumerator();
            while (ieKeys.MoveNext()) {
                TransportablePublicKey tpkKey = (TransportablePublicKey)ieKeys.Current;
                if (tpkKey.PrimaryKey.KeyID == lKeyID) {
                    return tpkKey;
                }
                IEnumerator ieSubkeys = tpkKey.SubKeys.GetEnumerator();
                while (ieSubkeys.MoveNext()) {
                    CertifiedPublicSubkey cpsSubkey = (CertifiedPublicSubkey)ieSubkeys.Current;
                    if (cpsSubkey.Subkey.KeyID == lKeyID)
                        return tpkKey;
                }
            }

            if (remote) {
                ldapKeyFinder.KeyFinder kf = new ldapKeyFinder.KeyFinder();

                string key = kf.MyLDAPSearch(SharpPrivacyLibrary.LdapKeyServer, SharpPrivacyLibrary.LdapPort,"pgpkey","(pgpsignerid="+lKeyID.ToString("X")+")");
                if (key != null) {
                    ArmorTypes atType = new ArmorTypes();
                    string strKey = Armor.RemoveArmor(key, ref atType, ref key);
                    if (strKey.Length > 0) {
                        TransportablePublicKey tpkKey = new TransportablePublicKey(strKey);
                        AddPublicKey(tpkKey);
                        return tpkKey;
                    }
                }
            }
            return null;
        }