pk.edu.niit.clarens.util
Class CertificateBlock

java.lang.Object
  extended bypk.edu.niit.clarens.util.PEMBlock
      extended bypk.edu.niit.clarens.util.CertificateBlock

public class CertificateBlock
extends PEMBlock

This class represents a PEM encoded certificate. Methods are provided for extracing the certificate object from the PEM block. This class should not be used directly. Use PEMBlock.getInstance(java.lang.String) to read arbitrary PEM data blocks and check the type of the returned blocks using PEMBlock.getType()


Field Summary
static java.lang.String FOOTER
           
static java.lang.String HEADER
           
protected  org.apache.log4j.Logger logger
           
 
Fields inherited from class pk.edu.niit.clarens.util.PEMBlock
base64BlockData, certificate, derBlockData, footer, header, PEM_CERTIFICATE, PEM_OPENSSL_DSA, PEM_OPENSSL_RSA, PEM_PKCS8_ENCRYPTED, PEM_PKCS8_UNENCRYPTED, PEM_UNKNOWN, PEMdata, privateKey, type, typeString
 
Constructor Summary
CertificateBlock(java.io.BufferedInputStream inputStream)
          Load a new PEM certificate from a stream of data.
CertificateBlock(java.lang.String data)
          Load a new PEM certificate from a string of data.
 
Method Summary
 java.security.cert.Certificate getCertificate()
          Get the certificate represented by this block.
 java.security.PrivateKey getPrivateKey()
          Get the private key from this block.
 java.security.PrivateKey getPrivateKey(java.lang.String passphrase)
          Get the private key from this block.
protected  void load(java.io.BufferedInputStream inputStream)
          Decode a PEM encoded block into more usable data.
protected  void load(java.lang.String data)
          Decode a PEM encoded block into more usable data.
 
Methods inherited from class pk.edu.niit.clarens.util.PEMBlock
getInstance, getInstance, getPem, getType, getTypeString, ReadBeginEnd, ReadBeginEnd
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEADER

public static final java.lang.String HEADER
See Also:
Constant Field Values

FOOTER

public static final java.lang.String FOOTER
See Also:
Constant Field Values

logger

protected org.apache.log4j.Logger logger
Constructor Detail

CertificateBlock

public CertificateBlock(java.lang.String data)
                 throws java.security.cert.CertificateException,
                        java.io.IOException
Load a new PEM certificate from a string of data. This constructor should not be used unless you are sure that the input source is a PEM certificate. Use PEMBlock.getInstance(java.lang.String) to read generic PEM data and have it cast to the appropriate type.

Parameters:
data - The string containing the PEM data.
Throws:
java.security.cert.CertificateException - Thrown if there was a problem validating the PEM data, or if there was a problem extracting the certificate from the PEM data.
java.io.IOException - Thrown if there was a problem decoding the base64 data.

CertificateBlock

public CertificateBlock(java.io.BufferedInputStream inputStream)
                 throws java.security.cert.CertificateException,
                        java.io.IOException
Load a new PEM certificate from a stream of data. This constructor should not be used unless you are sure that the input source is a PEM certificate. Use PEMBlock.getInstance(java.lang.String) to read generic PEM data and have it cast to the appropriate type.

Parameters:
inputStream - The data stream containing the certificate. If the input stream supports InputStream.mark(int) then the certificate's PEM header will be validated.
Throws:
java.security.cert.CertificateException - Thrown if there was a problem validating the PEM data, or if there was a problem extracting the certificate from the PEM data.
java.io.IOException - Thrown if there was a problem decoding the base64 data.
Method Detail

load

protected void load(java.io.BufferedInputStream inputStream)
             throws java.security.cert.CertificateException,
                    java.io.IOException
Decode a PEM encoded block into more usable data. The X509 certificate is created from the input data.

Parameters:
inputStream - The data stream containing the certificate. If the input stream supports InputStream.mark(int) then the certificate's PEM header will be validated.
Throws:
java.security.cert.CertificateException - Thrown if there was a problem validating the PEM data, or if there was a problem extracting the certificate from the PEM data.
java.io.IOException - Thrown if there was a problem decoding the base64 data.

load

protected void load(java.lang.String data)
             throws java.security.cert.CertificateException
Decode a PEM encoded block into more usable data. The X509 certificate is created from the input data.

Overrides:
load in class PEMBlock
Parameters:
data - The string containing the PEM encoded data.
Throws:
java.security.cert.CertificateException - Thrown if there was a problem validating the PEM data, or if there was a problem extracting the certificate from the PEM data.
java.io.IOException - Thrown if there was a problem decoding the base64 data.

getPrivateKey

public java.security.PrivateKey getPrivateKey()
                                       throws java.security.cert.CertificateException
Get the private key from this block. This returns null because this block type contains a certificate, not a private key.

Specified by:
getPrivateKey in class PEMBlock
Returns:
null. Always.
Throws:
java.security.cert.CertificateException - Never thrown.

getPrivateKey

public java.security.PrivateKey getPrivateKey(java.lang.String passphrase)
                                       throws java.security.cert.CertificateException
Get the private key from this block. This returns null because this block type contains a certificate, not a private key.

Specified by:
getPrivateKey in class PEMBlock
Returns:
null. Always.
Throws:
java.security.cert.CertificateException - Never thrown.

getCertificate

public java.security.cert.Certificate getCertificate()
Get the certificate represented by this block.

Specified by:
getCertificate in class PEMBlock
Returns:
The certificate represented by the block.