Class PEMReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Readable

    public class PEMReader
    extends java.io.BufferedReader
    Class for reading OpenSSL PEM encoded streams containing X509 certificates, PKCS8 encoded keys and PKCS7 objects.

    In the case of PKCS7 objects the reader will return a CMS ContentInfo object. Keys and Certificates will be returned using the appropriate java.security type.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private PasswordFinder pFinder  
      private java.lang.String provider  
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      PEMReader​(java.io.Reader reader)
      Create a new PEMReader
      PEMReader​(java.io.Reader reader, PasswordFinder pFinder)
      Create a new PEMReader with a password finder
      PEMReader​(java.io.Reader reader, PasswordFinder pFinder, java.lang.String provider)
      Create a new PEMReader with a password finder
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private X509AttributeCertificate readAttributeCertificate​(java.lang.String endMarker)
      Reads in a X509 Attribute Certificate.
      private byte[] readBytes​(java.lang.String endMarker)  
      private java.security.cert.X509Certificate readCertificate​(java.lang.String endMarker)
      Reads in a X509Certificate.
      private PKCS10CertificationRequest readCertificateRequest​(java.lang.String endMarker)
      Reads in a PKCS10 certification request.
      private java.security.cert.X509CRL readCRL​(java.lang.String endMarker)
      Reads in a X509CRL.
      private ECNamedCurveParameterSpec readECParameters​(java.lang.String endMarker)  
      private java.security.KeyPair readECPrivateKey​(java.lang.String endMarker)  
      private java.security.KeyPair readKeyPair​(java.lang.String type, java.lang.String endMarker)
      Read a Key Pair
      java.lang.Object readObject()  
      private ContentInfo readPKCS7​(java.lang.String endMarker)
      Reads in a PKCS7 object.
      private java.security.PublicKey readPublicKey​(java.lang.String endMarker)  
      private java.security.PublicKey readRSAPublicKey​(java.lang.String endMarker)  
      • Methods inherited from class java.io.BufferedReader

        close, lines, mark, markSupported, read, read, readLine, ready, reset, skip
      • Methods inherited from class java.io.Reader

        nullReader, read, read, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • provider

        private final java.lang.String provider
    • Constructor Detail

      • PEMReader

        public PEMReader​(java.io.Reader reader)
        Create a new PEMReader
        Parameters:
        reader - the Reader
      • PEMReader

        public PEMReader​(java.io.Reader reader,
                         PasswordFinder pFinder)
        Create a new PEMReader with a password finder
        Parameters:
        reader - the Reader
        pFinder - the password finder
      • PEMReader

        public PEMReader​(java.io.Reader reader,
                         PasswordFinder pFinder,
                         java.lang.String provider)
        Create a new PEMReader with a password finder
        Parameters:
        reader - the Reader
        pFinder - the password finder
        provider - the cryptography provider to use
    • Method Detail

      • readObject

        public java.lang.Object readObject()
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readBytes

        private byte[] readBytes​(java.lang.String endMarker)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readRSAPublicKey

        private java.security.PublicKey readRSAPublicKey​(java.lang.String endMarker)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • readPublicKey

        private java.security.PublicKey readPublicKey​(java.lang.String endMarker)
                                               throws java.io.IOException
        Throws:
        java.io.IOException
      • readCertificate

        private java.security.cert.X509Certificate readCertificate​(java.lang.String endMarker)
                                                            throws java.io.IOException
        Reads in a X509Certificate.
        Returns:
        the X509Certificate
        Throws:
        java.io.IOException - if an I/O error occured
      • readCRL

        private java.security.cert.X509CRL readCRL​(java.lang.String endMarker)
                                            throws java.io.IOException
        Reads in a X509CRL.
        Returns:
        the X509Certificate
        Throws:
        java.io.IOException - if an I/O error occured
      • readCertificateRequest

        private PKCS10CertificationRequest readCertificateRequest​(java.lang.String endMarker)
                                                           throws java.io.IOException
        Reads in a PKCS10 certification request.
        Returns:
        the certificate request.
        Throws:
        java.io.IOException - if an I/O error occured
      • readAttributeCertificate

        private X509AttributeCertificate readAttributeCertificate​(java.lang.String endMarker)
                                                           throws java.io.IOException
        Reads in a X509 Attribute Certificate.
        Returns:
        the X509 Attribute Certificate
        Throws:
        java.io.IOException - if an I/O error occured
      • readPKCS7

        private ContentInfo readPKCS7​(java.lang.String endMarker)
                               throws java.io.IOException
        Reads in a PKCS7 object. This returns a ContentInfo object suitable for use with the CMS API.
        Returns:
        the X509Certificate
        Throws:
        java.io.IOException - if an I/O error occured
      • readKeyPair

        private java.security.KeyPair readKeyPair​(java.lang.String type,
                                                  java.lang.String endMarker)
                                           throws java.lang.Exception
        Read a Key Pair
        Throws:
        java.lang.Exception
      • readECParameters

        private ECNamedCurveParameterSpec readECParameters​(java.lang.String endMarker)
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readECPrivateKey

        private java.security.KeyPair readECPrivateKey​(java.lang.String endMarker)
                                                throws java.io.IOException
        Throws:
        java.io.IOException