Decrypt() public method

public Decrypt ( SafePasswordHandle password ) : void
password Microsoft.Win32.SafeHandles.SafePasswordHandle
return void
Example #1
0
        private static IStorePal PfxToCollection(OpenSslPkcs12Reader pfx, string password)
        {
            pfx.Decrypt(password);

            X509Certificate2Collection coll = new X509Certificate2Collection();

            foreach (OpenSslX509CertificateReader certPal in pfx.ReadCertificates())
            {
                coll.Add(new X509Certificate2(certPal));
            }

            return(new OpenSslX509StoreProvider(coll));
        }
        private static bool TryReadPkcs12(
            OpenSslPkcs12Reader pfx,
            string password,
            bool single,
            out ICertificatePal readPal,
            out List <ICertificatePal> readCerts)
        {
            pfx.Decrypt(password);

            ICertificatePal        first = null;
            List <ICertificatePal> certs = null;

            if (!single)
            {
                certs = new List <ICertificatePal>();
            }

            foreach (OpenSslX509CertificateReader certPal in pfx.ReadCertificates())
            {
                if (single)
                {
                    // When requesting an X509Certificate2 from a PFX only the first entry is
                    // returned.  Other entries should be disposed.

                    if (first == null)
                    {
                        first = certPal;
                    }
                    else if (certPal.HasPrivateKey && !first.HasPrivateKey)
                    {
                        first.Dispose();
                        first = certPal;
                    }
                    else
                    {
                        certPal.Dispose();
                    }
                }
                else
                {
                    certs.Add(certPal);
                }
            }

            readPal   = first;
            readCerts = certs;
            return(true);
        }
Example #3
0
        private static bool TryReadPkcs12(
            OpenSslPkcs12Reader pfx,
            SafePasswordHandle password,
            bool single,
            bool ephemeralSpecified,
            out ICertificatePal?readPal,
            out List <ICertificatePal>?readCerts)
        {
            pfx.Decrypt(password, ephemeralSpecified);

            if (single)
            {
                UnixPkcs12Reader.CertAndKey  certAndKey = pfx.GetSingleCert();
                OpenSslX509CertificateReader pal        = (OpenSslX509CertificateReader)certAndKey.Cert !;

                if (certAndKey.Key != null)
                {
                    pal.SetPrivateKey(OpenSslPkcs12Reader.GetPrivateKey(certAndKey.Key));
                }

                readPal   = pal;
                readCerts = null;
                return(true);
            }

            readPal = null;
            List <ICertificatePal> certs = new List <ICertificatePal>(pfx.GetCertCount());

            foreach (UnixPkcs12Reader.CertAndKey certAndKey in pfx.EnumerateAll())
            {
                OpenSslX509CertificateReader pal = (OpenSslX509CertificateReader)certAndKey.Cert !;

                if (certAndKey.Key != null)
                {
                    pal.SetPrivateKey(OpenSslPkcs12Reader.GetPrivateKey(certAndKey.Key));
                }

                certs.Add(pal);
            }

            readCerts = certs;
            return(true);
        }
Example #4
0
        private static bool TryReadPkcs12(
            OpenSslPkcs12Reader pfx,
            string password,
            bool single,
            out ICertificatePal readPal,
            out List<ICertificatePal> readCerts)
        {
            pfx.Decrypt(password);

            ICertificatePal first = null;
            List<ICertificatePal> certs = null;

            if (!single)
            {
                certs = new List<ICertificatePal>();
            }

            foreach (OpenSslX509CertificateReader certPal in pfx.ReadCertificates())
            {
                if (single)
                {
                    // When requesting an X509Certificate2 from a PFX only the first entry is
                    // returned.  Other entries should be disposed.

                    if (first == null)
                    {
                        first = certPal;
                    }
                    else if (certPal.HasPrivateKey && !first.HasPrivateKey)
                    {
                        first.Dispose();
                        first = certPal;
                    }
                    else
                    {
                        certPal.Dispose();
                    }
                }
                else
                {
                    certs.Add(certPal);
                }
            }

            readPal = first;
            readCerts = certs;
            return true;
        }
Example #5
0
        private static IStorePal PfxToCollection(OpenSslPkcs12Reader pfx, string password)
        {
            pfx.Decrypt(password);

            X509Certificate2Collection coll = new X509Certificate2Collection();

            foreach (OpenSslX509CertificateReader certPal in pfx.ReadCertificates())
            {
                coll.Add(new X509Certificate2(certPal));
            }

            return new OpenSslX509StoreProvider(coll);
        }