Esempio n. 1
0
        public static string GetFileSubjectValue(string fileName, string keyName)
        {
            X509Certificate cert = X509Certificate.CreateFromSignedFile(fileName);
            Tokenizer t = new Tokenizer(cert.Subject);

            while (true)
            {
                t.EatWhitespace();
                string key = t.EatId();

                if (string.IsNullOrEmpty(key))
                    return null;

                t.EatWhitespace();
                string equals = t.EatSymbol();

                if (equals != "=")
                    return null;

                t.EatWhitespace();
                string value = t.EatQuotedString();

                if (string.IsNullOrEmpty(value))
                {

                    value = t.EatUntil(',');
                }

                if (string.IsNullOrEmpty(value))
                    return null;

                if (key == keyName)
                    return value;
            }
        }
        private static string GetX500Value(string subject, string keyName)
        {
            Tokenizer t = new Tokenizer(subject);

            // Use the "tokenizer" to get the Common Name (CN).
            while (true)
            {
                t.EatWhitespace();

                string key = t.EatId();

                if (string.IsNullOrEmpty(key))
                    return null;

                t.EatWhitespace();
                string equals = t.EatSymbol();

                if (equals != "=")
                    return null;

                t.EatWhitespace();
                string value = t.EatQuotedString();

                if (string.IsNullOrEmpty(value))
                {
                    // The value probably isn't quoted.
                    value = t.EatUntil(',');
                }

                if (string.IsNullOrEmpty(value))
                    return null;

                if (key == keyName)
                    return value;

                string comma = t.EatSymbol();

                if (comma != ",")
                    return null;
            }
        }