Re: How do I convert org.mozilla.jss.pkix.cert to org.mozilla.jss.crypto.X509Certificate?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I convert org.mozilla.jss.pkix.cert to org.mozilla.jss.crypto.X509Certificate?

Ernie Kovak
Try this:

    /** Convert an NSS certificate to a Java X509Certificate */
        protected X509Certificate convertNssCertificate(org.mozilla.jss.crypto.X509Certificate cert) throws CertificateException {
                InputStream in = null;
                try {
                        byte[] encodedCert = cert.getEncoded();
                        in = new ByteArrayInputStream(encodedCert);
                        X509Certificate x509Cert = (X509Certificate)CertificateFactory.getInstance("X.509").generateCertificate(in);
                        return x509Cert;
                } finally {
                        if (in != null) try { in.close(); } catch (IOException ignore) {}
                }
        }
--
dev-tech-crypto mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-crypto
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How do I convert org.mozilla.jss.pkix.cert to org.mozilla.jss.crypto.X509Certificate?

Elio Maldonado-2
Hi Ernie,

Not sure I fully understand the question. Without additional context is
hard to give a good answer.

Now, in one of the JSS tests I see code quite similar to the snippet you
pasted.
https://hg.mozilla.org/projects/jss/file/tip/org/
mozilla/jss/tests/ListCerts.java#l63
Hopefully studying that test and how it is invoked will help you.

Elio


On Thu, May 25, 2017 at 12:55 PM, Ernie Kovak <[hidden email]> wrote:

> Try this:
>
>     /** Convert an NSS certificate to a Java X509Certificate */
>         protected X509Certificate convertNssCertificate(org.
> mozilla.jss.crypto.X509Certificate cert) throws CertificateException {
>                 InputStream in = null;
>                 try {
>                         byte[] encodedCert = cert.getEncoded();
>                         in = new ByteArrayInputStream(encodedCert);
>                         X509Certificate x509Cert = (X509Certificate)
> CertificateFactory.getInstance("X.509").generateCertificate(in);
>                         return x509Cert;
>                 } finally {
>                         if (in != null) try { in.close(); } catch
> (IOException ignore) {}
>                 }
>         }
> --
> dev-tech-crypto mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-crypto
>
--
dev-tech-crypto mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-crypto
Loading...