org.eparapher.core.crypto.cert
Class X509Util

java.lang.Object
  extended by org.eparapher.core.crypto.cert.X509Util

public class X509Util
extends Object


Field Summary
static String BEGIN_CERT
           
static String BEGIN_CERT_REQ
           
static int CERT_LINE_LENGTH
           
static int CERT_REQ_LINE_LENGTH
           
static String END_CERT
           
static String END_CERT_REQ
           
 
Constructor Summary
X509Util()
           
 
Method Summary
static X509Certificate[] convertCertChaintoX509(Certificate[] certChain)
           
static byte[] fromHexString(String s)
          and be formed only of digits 0-9 A-F or a-f.
static Iterator<String> getAlgNames()
           
static X509Certificate getBCCertificate(X509Certificate cert)
          Convert any X509Certificate implementation from any Security Provider to BouncyCastle Security Provider implementation.
static String getCertBase64Encoded(X509Certificate cert)
          Return Certificate Base 64 Encoded (PEM format)
static byte[] getCertEncodedPkcs7(X509Certificate cert)
           
static CertificateFactory getCertificateFactory()
           
static byte[] getCertsEncodedPkcs7(X509Certificate[] certs)
           
static Collection<X509Certificate> getCertsFromPEM(InputStream certstream)
          Reads a certificate in PEM-format from an InputStream.
static Collection<X509Certificate> getCertsFromPEM(String certFile)
          Reads a certificate in PEM-format from a file.
static Collection<X509Certificate> getCertsFromPKCS7(String p7bfilename)
          Extract X509 Certificates from p7b files
static org.bouncycastle.asn1.x509.DistributionPoint[] getCrlDistributionPoint(X509Certificate certificate)
          Return the CRL distribution point URL form a certificate.
static org.bouncycastle.jce.PKCS10CertificationRequest getCSRFromPEM(String csrFile)
          Reads a certificate in PEM-format from an InputStream.
static String[] getECSpecsNames()
           
static org.bouncycastle.asn1.DERObject getExtensionValue(X509Certificate cert, String oid)
          Return an Extension DERObject from a certificate
static X509CRL loadCRLFromDP(org.bouncycastle.asn1.x509.DistributionPoint dp)
           
static boolean saveX509toFile(String filename, X509Certificate cert)
          Save a X509 Certificate to a file, in Base64 format
static String toHexString(byte[] b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BEGIN_CERT

public static final String BEGIN_CERT
See Also:
Constant Field Values

END_CERT

public static final String END_CERT
See Also:
Constant Field Values

CERT_LINE_LENGTH

public static final int CERT_LINE_LENGTH
See Also:
Constant Field Values

BEGIN_CERT_REQ

public static final String BEGIN_CERT_REQ
See Also:
Constant Field Values

END_CERT_REQ

public static final String END_CERT_REQ
See Also:
Constant Field Values

CERT_REQ_LINE_LENGTH

public static final int CERT_REQ_LINE_LENGTH
See Also:
Constant Field Values
Constructor Detail

X509Util

public X509Util()
Method Detail

getAlgNames

public static Iterator<String> getAlgNames()

getECSpecsNames

public static String[] getECSpecsNames()

getExtensionValue

public static org.bouncycastle.asn1.DERObject getExtensionValue(X509Certificate cert,
                                                                String oid)
                                                         throws IOException
Return an Extension DERObject from a certificate

Throws:
IOException

getCrlDistributionPoint

public static org.bouncycastle.asn1.x509.DistributionPoint[] getCrlDistributionPoint(X509Certificate certificate)
                                                                              throws CertificateParsingException
Return the CRL distribution point URL form a certificate.

Throws:
CertificateParsingException

convertCertChaintoX509

public static X509Certificate[] convertCertChaintoX509(Certificate[] certChain)

getCertBase64Encoded

public static String getCertBase64Encoded(X509Certificate cert)
Return Certificate Base 64 Encoded (PEM format)

Parameters:
cert -
Returns:

saveX509toFile

public static boolean saveX509toFile(String filename,
                                     X509Certificate cert)
Save a X509 Certificate to a file, in Base64 format

Parameters:
filename - The file that will certificate
cert - Certificate to save
Returns:

getCertsFromPKCS7

public static Collection<X509Certificate> getCertsFromPKCS7(String p7bfilename)
                                                     throws IOException,
                                                            CertificateException,
                                                            org.bouncycastle.cms.CMSException,
                                                            NoSuchProviderException,
                                                            org.bouncycastle.x509.NoSuchStoreException
Extract X509 Certificates from p7b files

Parameters:
p7bfilename -
Returns:
Throws:
IOException
CertificateException
org.bouncycastle.cms.CMSException
org.bouncycastle.x509.NoSuchStoreException
NoSuchProviderException

getCertsFromPEM

public static Collection<X509Certificate> getCertsFromPEM(String certFile)
                                                   throws IOException,
                                                          CertificateException
Reads a certificate in PEM-format from a file. The file may contain other things, the first certificate in the file is read.

Parameters:
certFile - the file containing the certificate in PEM-format
Returns:
Ordered Collection of X509Certificate, first certificate first, or empty Collection
Throws:
IOException - if the filen cannot be read.
CertificateException - if the filen does not contain a correct certificate.

getCertsFromPEM

public static Collection<X509Certificate> getCertsFromPEM(InputStream certstream)
                                                   throws IOException,
                                                          CertificateException
Reads a certificate in PEM-format from an InputStream. The stream may contain other things, the first certificate in the stream is read.

Parameters:
certFile - the input stream containing the certificate in PEM-format
Returns:
Ordered Collection of X509Certificate, first certificate first, or empty Collection
Throws:
IOException - if the stream cannot be read.
CertificateException - if the stream does not contain a correct certificate.

getCSRFromPEM

public static org.bouncycastle.jce.PKCS10CertificationRequest getCSRFromPEM(String csrFile)
                                                                     throws IOException,
                                                                            CertificateException
Reads a certificate in PEM-format from an InputStream. The stream may contain other things, the first certificate in the stream is read.

Parameters:
certFile - the input stream containing the certificate in PEM-format
Returns:
Ordered Collection of X509Certificate, first certificate first, or empty Collection
Throws:
IOException - if the stream cannot be read.
CertificateException - if the stream does not contain a correct certificate.

getCertEncodedPkcs7

public static byte[] getCertEncodedPkcs7(X509Certificate cert)

getCertsEncodedPkcs7

public static byte[] getCertsEncodedPkcs7(X509Certificate[] certs)

getCertificateFactory

public static CertificateFactory getCertificateFactory()

toHexString

public static String toHexString(byte[] b)

fromHexString

public static byte[] fromHexString(String s)
and be formed only of digits 0-9 A-F or a-f. No spaces, minus or plus signs.

Returns:
corresponding byte array.

getBCCertificate

public static X509Certificate getBCCertificate(X509Certificate cert)
Convert any X509Certificate implementation from any Security Provider to BouncyCastle Security Provider implementation.
If convertion failed for any reason, it return the input X509Certificate object.

Parameters:
cert - the certificate object to convert
Returns:
X509CertificateObject implementation of X509Certificate

loadCRLFromDP

public static X509CRL loadCRLFromDP(org.bouncycastle.asn1.x509.DistributionPoint dp)


Copyright © 2009 eParapher Software Foundation. All Rights Reserved.