System.Security.Cryptography.X509Certificates.X509Certificate2Collection.Import C# (CSharp) Method

Import() public method

public Import ( byte rawData ) : void
rawData byte
return void
        public void Import(byte[] rawData)
        {
        }

Same methods

X509Certificate2Collection::Import ( byte rawData, string password, System keyStorageFlags ) : void
X509Certificate2Collection::Import ( byte rawData, string password, X509KeyStorageFlags keyStorageFlags ) : void
X509Certificate2Collection::Import ( string fileName ) : void
X509Certificate2Collection::Import ( string fileName, string password, System keyStorageFlags ) : void
X509Certificate2Collection::Import ( string fileName, string password, X509KeyStorageFlags keyStorageFlags ) : void

Usage Example

        public void Execute(object parameter)
        {
            var pfx = CertificateManager.GeneratePfx(CertificateName, CertificatePassword);
            var certificate = CertificateManager.GetCertificateForBytes(pfx.GetBytes(), CertificatePassword);

            File.WriteAllBytes(Path.Combine(AppHelper.CachePath, "AzureAutomation.pfx"), pfx.GetBytes());
            File.WriteAllBytes(Path.Combine(AppHelper.CachePath, "AzureAutomation.cer"), certificate);

            var collection = new X509Certificate2Collection();
            collection.Import(Path.Combine(AppHelper.CachePath, "AzureAutomation.pfx"), CertificatePassword, X509KeyStorageFlags.PersistKeySet);

            var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadWrite);

            // Store the certificate
            foreach (var cert in collection)
                store.Add(cert);

            store.Close();

            // Delete the certificate that contains the private key - this is already imported into the cert store
            File.Delete(Path.Combine(AppHelper.CachePath, "AzureAutomation.pfx"));

            MessageBox.Show("The certificate has been generated. Please refresh the certificates list.", "Certificate", MessageBoxButton.OK);

            // Open the folder containing the certificate
            Process.Start("explorer.exe", AppHelper.CachePath);
        }
All Usage Examples Of System.Security.Cryptography.X509Certificates.X509Certificate2Collection::Import