org.apache.geronimo.util
Class CaUtils

java.lang.Object
  extended by org.apache.geronimo.util.CaUtils

public class CaUtils
extends Object

This class implements some utility methods used by CA


Field Summary
static int B64_LINE_SIZE
           
static String CERT_FOOTER
           
static String CERT_HEADER
           
static String CERT_REQ_HEADER
           
static String CERT_REQ_PUBLICKEY
           
static String CERT_REQ_PUBLICKEY_OBJ
           
static String CERT_REQ_SUBJECT
           
static String CERT_REQ_VERSION
           
static String PKAC_CHALLENGE
           
 
Constructor Summary
CaUtils()
           
 
Method Summary
static String base64Certificate(Certificate cert)
          This method returns base64 encoded text of a given certificate.
static String base64Text(byte[] data, String header, String footer, int lineSize)
          This method encodes a given byte array into base64 along with specified header and footers.
static PublicKey getPublicKeyObject(SubjectPublicKeyInfo pubKeyInfo)
          This method creates a java.security.PublicKey object based on the public key information given in SubjectPublicKeyInfo
static X509Name getSubjectX509Name(Certificate cert)
          This method returns a X509Name object corresponding to the subject in a given certificate
static X509Name getX509Name(String cn, String ou, String o, String l, String st, String c)
          This method creates a X509Name object using the name attributes specified.
static X509Name getX509Name(X500Principal principal)
          This method returns a X509Name object corresponding to a given principal
static Map processPKCS10Request(String certreq)
          This method processes a certificate request and returns a map containing subject and public key in the request.
static Map processSPKAC(String spkac)
          This method processes a DER encoded SignedPublicKeyAndChallenge in base64 format.
static void storeInBase64(OutputStream fout, byte[] data, String header, String footer, int lineSize)
          This method encodes a given byte array into base64 along with specified header and footers and writes the output to a specified OutputStream.
static void storeInBase64(String outfile, byte[] data, String header, String footer, int lineSize)
          This method encodes a given byte array into base64 along with specified header and footers and writes the output to a specified file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CERT_HEADER

public static final String CERT_HEADER
See Also:
Constant Field Values

CERT_FOOTER

public static final String CERT_FOOTER
See Also:
Constant Field Values

CERT_REQ_HEADER

public static final String CERT_REQ_HEADER
See Also:
Constant Field Values

B64_LINE_SIZE

public static final int B64_LINE_SIZE
See Also:
Constant Field Values

CERT_REQ_SUBJECT

public static final String CERT_REQ_SUBJECT
See Also:
Constant Field Values

CERT_REQ_PUBLICKEY

public static final String CERT_REQ_PUBLICKEY
See Also:
Constant Field Values

CERT_REQ_PUBLICKEY_OBJ

public static final String CERT_REQ_PUBLICKEY_OBJ
See Also:
Constant Field Values

CERT_REQ_VERSION

public static final String CERT_REQ_VERSION
See Also:
Constant Field Values

PKAC_CHALLENGE

public static final String PKAC_CHALLENGE
See Also:
Constant Field Values
Constructor Detail

CaUtils

public CaUtils()
Method Detail

base64Certificate

public static String base64Certificate(Certificate cert)
                                throws CertificateEncodingException,
                                       Exception
This method returns base64 encoded text of a given certificate.

Parameters:
cert - The certificate that needs to be encoded in base64
Throws:
CertificateEncodingException
Exception

base64Text

public static String base64Text(byte[] data,
                                String header,
                                String footer,
                                int lineSize)
                         throws Exception
This method encodes a given byte array into base64 along with specified header and footers.

Parameters:
data - The byte array to be encoded in base64
header - Header for base64 encoded text
footer - Footer for base64 encoded text
lineSize - Maximum line size to split base64 encoded text if required
Throws:
Exception

storeInBase64

public static void storeInBase64(OutputStream fout,
                                 byte[] data,
                                 String header,
                                 String footer,
                                 int lineSize)
                          throws Exception
This method encodes a given byte array into base64 along with specified header and footers and writes the output to a specified OutputStream.

Parameters:
fout - Output stream to write the encoded text
data - The byte array to be encoded in base64
header - Header for base64 encoded text
footer - Footer for base64 encoded text
lineSize - Maximum line size to split base64 encoded text if required
Throws:
Exception

storeInBase64

public static void storeInBase64(String outfile,
                                 byte[] data,
                                 String header,
                                 String footer,
                                 int lineSize)
                          throws Exception
This method encodes a given byte array into base64 along with specified header and footers and writes the output to a specified file.

Parameters:
outfile - File name to write the output to
data - The byte array to be encoded in base64
header - Header for base64 encoded text
footer - Footer for base64 encoded text
lineSize - Maximum line size to split base64 encoded text if required
Throws:
Exception

getPublicKeyObject

public static PublicKey getPublicKeyObject(SubjectPublicKeyInfo pubKeyInfo)
                                    throws Exception
This method creates a java.security.PublicKey object based on the public key information given in SubjectPublicKeyInfo

Parameters:
pubKeyInfo - SubjectPublicKeyInfo instance containing the public key information.
Throws:
Exception

getSubjectX509Name

public static X509Name getSubjectX509Name(Certificate cert)
                                   throws CertificateEncodingException,
                                          IOException
This method returns a X509Name object corresponding to the subject in a given certificate

Parameters:
cert - Certificate from which subject needs to be retrieved
Throws:
CertificateEncodingException
IOException

getX509Name

public static X509Name getX509Name(X500Principal principal)
                            throws CertificateEncodingException,
                                   IOException
This method returns a X509Name object corresponding to a given principal

Throws:
CertificateEncodingException
IOException

processPKCS10Request

public static Map processPKCS10Request(String certreq)
                                throws InvalidKeyException,
                                       NoSuchAlgorithmException,
                                       NoSuchProviderException,
                                       SignatureException,
                                       Exception
This method processes a certificate request and returns a map containing subject and public key in the request.

Parameters:
certreq - base64 encoded PKCS10 certificate request
Throws:
InvalidKeyException
NoSuchAlgorithmException
NoSuchProviderException
SignatureException
Exception

processSPKAC

public static Map processSPKAC(String spkac)
                        throws IOException,
                               NoSuchAlgorithmException,
                               InvalidKeyException,
                               SignatureException,
                               Exception
This method processes a DER encoded SignedPublicKeyAndChallenge in base64 format.

Parameters:
spkac - SignedPublicKeyAndChallenge in base64 text format
Returns:
a Map with Subject, public-key and challenge
Throws:
IOException
NoSuchAlgorithmException
InvalidKeyException
SignatureException
Exception

getX509Name

public static X509Name getX509Name(String cn,
                                   String ou,
                                   String o,
                                   String l,
                                   String st,
                                   String c)
This method creates a X509Name object using the name attributes specified.

Parameters:
cn - Common Name
ou - Organization Unit
o - Organization
l - Locality
st - State
c - Country


Copyright © 2003-2007 Apache Software Foundation. All Rights Reserved.