Esempio n. 1
0
        private static string PromptForCertificate(string m_sCertFile, string m_sFilePassword, KeyType m_KeyType)
        {
            Hashtable hCertificates = null;
            Hashtable hEnumHash     = new Hashtable();

            if (m_KeyType == KeyType.PRIVATE)
            {
                hCertificates = PrivateKeyManager.EnumerateCerts(m_sCertFile, m_sFilePassword);
            }
            else if (m_KeyType == KeyType.ROOT || m_KeyType == KeyType.PUBLIC || m_KeyType == KeyType.INTER)
            {
                hCertificates = PrivateKeyManager.EnumeratePublicCerts(m_sCertFile);
            }

            if (hCertificates.Keys.Count == 1)
            {
                Console.WriteLine("The available certificate is:\r\n");
            }
            else
            {
                Console.WriteLine("Select the certificate to import from the list below:\r\n");
            }

            int iCounter = 1;

            foreach (string sHashID in hCertificates.Keys)
            {
                Console.WriteLine(iCounter + "- " + hCertificates[sHashID].ToString() + "\r\nThumbprint: " + sHashID + "\r\n");
                hEnumHash.Add(iCounter++, sHashID);
            }

            int iChoice = 1;

            if (hCertificates.Keys.Count > 1)
            {
                Console.Write("\r\nEnter certificate number 1-" + (iCounter - 1) + " (default 1): ");

                string sChoice = Console.ReadLine();
                if (string.IsNullOrEmpty(sChoice))
                {
                    sChoice = "1";
                }

                try
                {
                    iChoice = System.Convert.ToInt16(sChoice, CultureInfo.InvariantCulture);
                }
                catch
                {
                    iChoice = 1;
                }
                if (iChoice < 1 || iChoice > iCounter - 1)
                {
                    iChoice = 1;
                }
            }
            return(hEnumHash[iChoice].ToString());
        }