com.cafesoft.core.util
Class X509CertificateUtils

java.lang.Object
  extended by com.cafesoft.core.util.X509CertificateUtils

public class X509CertificateUtils
extends Object

X509CertificateUtils provides various convenience utilities for managing X509Certificate instances.

Since:
08/24/2005

Field Summary
static String PEM_BEGIN_CERTIFICATE_DELIMITER
          The PEM string that indicates the beginning of a PEM-formatted certificate.
static String PEM_END_CERTIFICATE_DELIMITER
          The PEM string that indicates the end of a PEM-formatted certificate.
 
Constructor Summary
X509CertificateUtils()
           
 
Method Summary
static X509Certificate[] decodeChainFromPEM(File pemFile)
          Decode an X509Certificate chain from a PEM formatted File.
static X509Certificate[] decodeChainFromPEM(InputStream is)
          Decode an X509Certificate chain from a PEM formatted InputStream.
static X509Certificate[] decodeChainFromPEM(String pemCert)
          Decode an X509Certificate chain from a PEM formatted String.
static X509Certificate decodeFromPEM(File pemFile)
          Decode a single X509Certificate from a PEM formatted File.
static X509Certificate decodeFromPEM(InputStream is)
          Decode an X509Certificate from a PEM formatted InputStream.
static X509Certificate decodeFromPEM(String pemCert)
          Decode an X509Certificate from a PEM formatted String.
static void encodeAsPEM(X509Certificate cert, StringBuffer b)
          Encode a single X509Certificate in PEM format and append to a StringBuffer.
static void encodeChainAsPEM(X509Certificate[] certArray, StringBuffer b)
          Encode an X509Certificate chain in PEM format and append to a StringBuffer.
static PKIXCertPathValidatorResult validate(X509Certificate[] chain, X509Certificate caCert)
          Validate an X509Certificate chain.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PEM_BEGIN_CERTIFICATE_DELIMITER

public static String PEM_BEGIN_CERTIFICATE_DELIMITER
The PEM string that indicates the beginning of a PEM-formatted certificate.


PEM_END_CERTIFICATE_DELIMITER

public static String PEM_END_CERTIFICATE_DELIMITER
The PEM string that indicates the end of a PEM-formatted certificate.

Constructor Detail

X509CertificateUtils

public X509CertificateUtils()
Method Detail

encodeAsPEM

public static void encodeAsPEM(X509Certificate cert,
                               StringBuffer b)
                        throws CertificateEncodingException
Encode a single X509Certificate in PEM format and append to a StringBuffer.

Parameters:
cert - the X509Certificate instance.
b - the StringBuffer.
Throws:
CertificateEncodingException - if the certificate or StringBuffer is null or and encoding error occurs.

decodeFromPEM

public static X509Certificate decodeFromPEM(String pemCert)
                                     throws CertificateException
Decode an X509Certificate from a PEM formatted String.

Parameters:
pemCert - the PEM-formatted X509Certificate chain.
Returns:
an array of X509Certificates.
Throws:
CertificateException - if unable to decode the certificate chain.

decodeFromPEM

public static X509Certificate decodeFromPEM(File pemFile)
                                     throws CertificateException
Decode a single X509Certificate from a PEM formatted File.

Parameters:
pemFile - the File containing the PEM-formatted X509Certificate.
Returns:
a single X509Certificate.
Throws:
CertificateException - if unable to decode the certificate.

decodeFromPEM

public static X509Certificate decodeFromPEM(InputStream is)
                                     throws CertificateException
Decode an X509Certificate from a PEM formatted InputStream.

Parameters:
is - the PEM-formatted X509Certificate InputStream.
Returns:
a single X509Certificate.
Throws:
CertificateException - if unable to decode the certificate from the InputStream.

encodeChainAsPEM

public static void encodeChainAsPEM(X509Certificate[] certArray,
                                    StringBuffer b)
                             throws CertificateEncodingException
Encode an X509Certificate chain in PEM format and append to a StringBuffer.

Parameters:
certArray - the X509Certificate chain.
b - the StringBuffer.
Throws:
CertificateEncodingException - if the certificate or StringBuffer is null or and encoding error occurs.

decodeChainFromPEM

public static X509Certificate[] decodeChainFromPEM(String pemCert)
                                            throws CertificateException
Decode an X509Certificate chain from a PEM formatted String.

Parameters:
pemCert - the PEM-formatted X509Certificate chain.
Returns:
an array of X509Certificates.
Throws:
CertificateException - if unable to decode the certificate chain.

decodeChainFromPEM

public static X509Certificate[] decodeChainFromPEM(InputStream is)
                                            throws CertificateException
Decode an X509Certificate chain from a PEM formatted InputStream.

Parameters:
is - the InputStream containing the PEM-formatted X509Certificate chain.
Returns:
an array of X509Certificates decoded from the InputStream.
Throws:
CertificateException - if unable to decode the certificate chain.

decodeChainFromPEM

public static X509Certificate[] decodeChainFromPEM(File pemFile)
                                            throws CertificateException
Decode an X509Certificate chain from a PEM formatted File.

Parameters:
pemFile - the File containing the PEM-formatted X509Certificate chain.
Returns:
an array of X509Certificates.
Throws:
CertificateException - if unable to decode the certificate chain.

validate

public static PKIXCertPathValidatorResult validate(X509Certificate[] chain,
                                                   X509Certificate caCert)
                                            throws CertPathValidatorException,
                                                   CertificateException,
                                                   NoSuchAlgorithmException,
                                                   InvalidAlgorithmParameterException
Validate an X509Certificate chain.

Parameters:
chain - the X509Certificate chain to be validated.
caCert - the trusted Certificate Authority X509 certificate.
Returns:
a PKIXCertPathValidatorResult object if the certificate chain is valid.
Throws:
CertificatePathValidatorException - if the X509Certificate chain is invalid.
CertificateException - if a CertificateFactory is not available for X509 certificates in the default cryptography package.
NoSuchAlgorithmException - if the PKIX certificate path algorithm is not available in the default cryptography provider package or any of the other provider packages that were searched
InvalidAlgorithmException - if the X509 certificate chain is not compatible with the PKIX certificate path validator.
CertPathValidatorException
InvalidAlgorithmParameterException
See Also:
X509Certificate, CertPathValidator, PKIXCertPathValidatorResult


Generated on 10:38:35 AM April 14, 2011, © 1996-2010 Cafésoft LLC. All rights reserved.