Beispiel #1
0
        public void AddRange(X509Certificate2Collection certificates)
        {
            if (certificates == null)
            {
                throw new ArgumentNullException("certificates");
            }

            if (certificates.Count == 0)
            {
                return;
            }

            if (!IsOpen)
            {
                throw new CryptographicException(Locale.GetText("Store isn't opened."));
            }
            if (IsReadOnly)
            {
                throw new CryptographicException(Locale.GetText("Store is read-only."));
            }

            foreach (X509Certificate2 certificate in certificates)
            {
                if (!Exists(certificate))
                {
                    try {
                        store.Import(new MX.X509Certificate(certificate.RawData));
                    }
                    finally {
                        CertList.Add(certificate);
                    }
                }
            }
        }
Beispiel #2
0
        // methods

        public void Add(X509Certificate2 certificate)
        {
            if (certificate == null)
            {
                throw new ArgumentNullException("certificate");
            }
            if (!IsOpen)
            {
                throw new CryptographicException(Locale.GetText("Store isn't opened."));
            }
            if (IsReadOnly)
            {
                throw new CryptographicException(Locale.GetText("Store is read-only."));
            }

            if (!Exists(certificate))
            {
                try {
                    store.Import(new MX.X509Certificate(certificate.RawData));
                }
                finally {
                    CertList.Add(certificate);
                }
            }
        }
Beispiel #3
0
        public void Open(OpenFlags flags)
        {
            if (String.IsNullOrEmpty(_name))
            {
                throw new CryptographicException(Locale.GetText("Invalid store name (null or empty)."));
            }

            /* keep existing Mono installations (pre 2.0) compatible with new stuff */
            string name;

            switch (_name)
            {
            case "Root":
                name = "Trust";
                break;

            default:
                name = _name;
                break;
            }

            bool create = ((flags & OpenFlags.OpenExistingOnly) != OpenFlags.OpenExistingOnly);

            store = Factory.Open(name, create);
            if (store == null)
            {
                throw new CryptographicException(Locale.GetText("Store {0} doesn't exists.", _name));
            }
            _flags = flags;

            foreach (MX.X509Certificate x in store.Certificates)
            {
                var cert2 = new X509Certificate2(x.RawData);
                cert2.PrivateKey = x.RSA;
                CertList.Add(cert2);
            }
        }