Exemplo n.º 1
0
 public byte[] Export(X509ContentType contentType, String password)
 {
     using (IStorePal storePal = StorePal.LinkFromCertificateCollection(this))
     {
         return(storePal.Export(contentType, password));
     }
 }
Exemplo n.º 2
0
 public byte[]? Export(X509ContentType contentType, string?password)
 {
     using (var safePasswordHandle = new SafePasswordHandle(password))
         using (IExportPal storePal = StorePal.LinkFromCertificateCollection(this))
         {
             return(storePal.Export(contentType, safePasswordHandle));
         }
 }
Exemplo n.º 3
0
 public byte[] Export(X509ContentType contentType, SafePasswordHandle password)
 {
     using (IExportPal storePal = StorePal.FromCertificate(this))
     {
         byte[]? exported = storePal.Export(contentType, password);
         Debug.Assert(exported != null);
         return(exported);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        ///   Imports the certificates from the provided data into this collection.
        /// </summary>
        /// <param name="rawData">
        ///   The certificate data to read.
        /// </param>
        /// <param name="password">
        ///   The password required to access the certificate data.
        /// </param>
        /// <param name="keyStorageFlags">
        ///   A bitwise combination of the enumeration values that control where and how to import the certificate.
        /// </param>
        public void Import(ReadOnlySpan <byte> rawData, ReadOnlySpan <char> password, X509KeyStorageFlags keyStorageFlags = 0)
        {
            X509Certificate.ValidateKeyStorageFlags(keyStorageFlags);

            using (var safePasswordHandle = new SafePasswordHandle(password))
                using (ILoaderPal storePal = StorePal.FromBlob(rawData, safePasswordHandle, keyStorageFlags))
                {
                    storePal.MoveTo(this);
                }
        }
Exemplo n.º 5
0
        public void Import(byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
        {
            if (rawData == null)
            {
                throw new ArgumentNullException("rawData");
            }

            using (IStorePal storePal = StorePal.FromBlob(rawData, password, keyStorageFlags))
            {
                storePal.CopyTo(this);
            }
        }
        public void Import(byte[] rawData, string password, X509KeyStorageFlags keyStorageFlags)
        {
            if (rawData == null)
            {
                throw new ArgumentNullException(nameof(rawData));
            }

            using (ILoaderPal storePal = StorePal.FromBlob(rawData, password, keyStorageFlags))
            {
                storePal.MoveTo(this);
            }
        }
Exemplo n.º 7
0
        public void Import(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            using (IStorePal storePal = StorePal.FromFile(fileName, password, keyStorageFlags))
            {
                storePal.CopyTo(this);
            }
        }
        public void Import(string fileName, string password, X509KeyStorageFlags keyStorageFlags)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            using (ILoaderPal storePal = StorePal.FromFile(fileName, password, keyStorageFlags))
            {
                storePal.MoveTo(this);
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///   Imports the certificates from the specified file a into this collection.
        /// </summary>
        /// <param name="fileName">
        ///   The name of the file containing the certificate information.
        /// </param>
        /// <param name="password">
        ///   The password required to access the certificate data.
        /// </param>
        /// <param name="keyStorageFlags">
        ///   A bitwise combination of the enumeration values that control where and how to import the certificate.
        /// </param>
        public void Import(string fileName, ReadOnlySpan <char> password, X509KeyStorageFlags keyStorageFlags = 0)
        {
            ArgumentNullException.ThrowIfNull(fileName);

            X509Certificate.ValidateKeyStorageFlags(keyStorageFlags);

            using (var safePasswordHandle = new SafePasswordHandle(password))
                using (ILoaderPal storePal = StorePal.FromFile(fileName, safePasswordHandle, keyStorageFlags))
                {
                    storePal.MoveTo(this);
                }
        }
Exemplo n.º 10
0
        public virtual byte[] Export(X509ContentType contentType, SecureString password)
        {
            VerifyContentType(contentType);

            if (Pal == null)
            {
                throw new CryptographicException(ErrorCode.E_POINTER);  // Not the greatest error, but needed for backward compat.
            }
            using (var safePasswordHandle = new SafePasswordHandle(password))
                using (IExportPal storePal = StorePal.FromCertificate(Pal))
                {
                    return(storePal.Export(contentType, safePasswordHandle));
                }
        }
Exemplo n.º 11
0
        public X509Certificate2Collection Find(X509FindType findType, Object findValue, bool validOnly)
        {
            if (findValue == null)
            {
                throw new ArgumentNullException("findValue");
            }

            X509Certificate2Collection collection = new X509Certificate2Collection();

            using (IStorePal storePal = StorePal.LinkFromCertificateCollection(this))
            {
                storePal.FindAndCopyTo(findType, findValue, validOnly, collection);
            }
            return(collection);
        }
Exemplo n.º 12
0
        /// <summary>
        ///   Imports the certificates from the provided data into this collection.
        /// </summary>
        /// <param name="rawData">
        ///   The certificate data to read.
        /// </param>
        /// <param name="password">
        ///   The password required to access the certificate data.
        /// </param>
        /// <param name="keyStorageFlags">
        ///   A bitwise combination of the enumeration values that control where and how to import the certificate.
        /// </param>
        public void Import(ReadOnlySpan <byte> rawData, ReadOnlySpan <char> password, X509KeyStorageFlags keyStorageFlags = 0)
        {
            if (rawData == null)
            {
                throw new ArgumentNullException(nameof(rawData));
            }

            X509Certificate.ValidateKeyStorageFlags(keyStorageFlags);

            using (var safePasswordHandle = new SafePasswordHandle(password))
                using (ILoaderPal storePal = StorePal.FromBlob(rawData, safePasswordHandle, keyStorageFlags))
                {
                    storePal.MoveTo(this);
                }
        }
Exemplo n.º 13
0
        public void Import(string fileName, string?password, X509KeyStorageFlags keyStorageFlags = 0)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            X509Certificate.ValidateKeyStorageFlags(keyStorageFlags);

            using (var safePasswordHandle = new SafePasswordHandle(password))
                using (ILoaderPal storePal = StorePal.FromFile(fileName, safePasswordHandle, keyStorageFlags))
                {
                    storePal.MoveTo(this);
                }
        }
Exemplo n.º 14
0
        public virtual byte[] Export(X509ContentType contentType, string password)
        {
            if (!(contentType == X509ContentType.Cert || contentType == X509ContentType.SerializedCert || contentType == X509ContentType.Pkcs12))
            {
                throw new CryptographicException(SR.Cryptography_X509_InvalidContentType);
            }

            if (Pal == null)
            {
                throw new CryptographicException(ErrorCode.E_POINTER);  // Not the greatest error, but needed for backward compat.
            }
            using (IExportPal storePal = StorePal.FromCertificate(Pal))
            {
                return(storePal.Export(contentType, password));
            }
        }
Exemplo n.º 15
0
        public void Import(String fileName, String password, X509KeyStorageFlags keyStorageFlags)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            using (IStorePal storePal = StorePal.FromFile(fileName, password, keyStorageFlags))
            {
                foreach (X509Certificate2 cert in storePal.Certificates)
                {
                    Add(cert);
                }
            }
            return;
        }
Exemplo n.º 16
0
        public void Import(byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
        {
            if (rawData == null)
            {
                throw new ArgumentNullException("rawData");
            }

            using (IStorePal storePal = StorePal.FromBlob(rawData, password, keyStorageFlags))
            {
                foreach (X509Certificate2 cert in storePal.Certificates)
                {
                    Add(cert);
                }
            }
            return;
        }
Exemplo n.º 17
0
        internal static partial IStorePal FromHandle(IntPtr storeHandle)
        {
            if (storeHandle == IntPtr.Zero)
            {
                throw new ArgumentNullException(nameof(storeHandle));
            }

            SafeCertStoreHandle certStoreHandle = Interop.Crypt32.CertDuplicateStore(storeHandle);

            if (certStoreHandle == null || certStoreHandle.IsInvalid)
            {
                throw new CryptographicException(SR.Cryptography_InvalidStoreHandle, nameof(storeHandle));
            }

            var pal = new StorePal(certStoreHandle);

            return(pal);
        }
Exemplo n.º 18
0
 public void Open(OpenFlags flags)
 {
     Close();
     _storePal = StorePal.FromSystemStore(Name, Location, flags);
 }
Exemplo n.º 19
0
 public X509Store(IntPtr storeHandle)
 {
     _storePal = StorePal.FromHandle(storeHandle);
     Debug.Assert(_storePal != null);
 }
Exemplo n.º 20
0
 private FindPal(X509Certificate2Collection findFrom, X509Certificate2Collection copyTo, bool validOnly)
 {
     _storePal  = (StorePal)StorePal.LinkFromCertificateCollection(findFrom);
     _copyTo    = copyTo;
     _validOnly = validOnly;
 }