nl.nikhef.slcshttps.crypto
Class CSR

java.lang.Object
  extended by org.bouncycastle.asn1.ASN1Encodable
      extended by org.bouncycastle.asn1.pkcs.CertificationRequest
          extended by org.bouncycastle.jce.PKCS10CertificationRequest
              extended by nl.nikhef.slcshttps.crypto.CSR
All Implemented Interfaces:
DEREncodable

public class CSR
extends PKCS10CertificationRequest

This class is a holder for a PKCS10 Certificate Signing Request, which also supplies methods to obtain a SHA1 hash of its DER encoding and a method to obtain a URL encoded PEM string.

Version:
0.1
Author:
Mischa Sallé

Field Summary
protected static String DUMMY_DN
          Default subject DN certificate signing requests is "C=X, O=Y, CN=Z".
 
Fields inherited from class org.bouncycastle.asn1.pkcs.CertificationRequest
reqInfo, sigAlgId, sigBits
 
Fields inherited from class org.bouncycastle.asn1.ASN1Encodable
BER, DER
 
Constructor Summary
CSR(PublicKey pubKey, PrivateKey privKey)
          Constructs a Certificate Signing Request for the keypair using a default DUMMY_DN (="C=X, O=Y, CN=Z").
CSR(String subjectDN, PublicKey pubKey, PrivateKey privKey)
          Constructs a Certificate Signing Request for the given keypair using specified subjectDN.
 
Method Summary
private  String bytetoString(byte[] bytes)
          returns a String representation of the given byte[] array.
 String hash()
          Returns the SHA1 hash for the DER encoded CSR.
 String pemString()
          Returns a PEMstring for the CSR as a URL encoded (UTF-8) String.
 
Methods inherited from class org.bouncycastle.jce.PKCS10CertificationRequest
getEncoded, getPublicKey, getPublicKey, verify, verify, verify
 
Methods inherited from class org.bouncycastle.asn1.pkcs.CertificationRequest
getCertificationRequestInfo, getInstance, getSignature, getSignatureAlgorithm, toASN1Object
 
Methods inherited from class org.bouncycastle.asn1.ASN1Encodable
equals, getDEREncoded, getDERObject, getEncoded, hashCode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DUMMY_DN

protected static final String DUMMY_DN
Default subject DN certificate signing requests is "C=X, O=Y, CN=Z".

See Also:
Constant Field Values
Constructor Detail

CSR

public CSR(String subjectDN,
           PublicKey pubKey,
           PrivateKey privKey)
    throws NoSuchAlgorithmException,
           NoSuchProviderException,
           InvalidKeyException,
           SignatureException
Constructs a Certificate Signing Request for the given keypair using specified subjectDN. It uses SHA1/RSA as signature algorithm.

Parameters:
subjectDN - specifies the subject DN to use for signing request.
pubKey - specifies public key of keypair to use for signing request.
privKey - specifies private key of keypair to use for signing request.
Throws:
NoSuchAlgorithmException
NoSuchProviderException
InvalidKeyException
SignatureException

CSR

public CSR(PublicKey pubKey,
           PrivateKey privKey)
    throws NoSuchAlgorithmException,
           NoSuchProviderException,
           InvalidKeyException,
           SignatureException
Constructs a Certificate Signing Request for the keypair using a default DUMMY_DN (="C=X, O=Y, CN=Z").

Parameters:
pubKey - specifies public key of keypair to use for signing request
privKey - specifies private key of keypair to use for signing request
Throws:
NoSuchAlgorithmException
NoSuchProviderException
InvalidKeyException
SignatureException
See Also:
CSR(String, PublicKey, PrivateKey)
Method Detail

pemString

public String pemString()
                 throws IOException
Returns a PEMstring for the CSR as a URL encoded (UTF-8) String.

Returns:
String representing URL encoded PEMstring.
Throws:
IOException - if construction of PEMstring fails
See Also:
URLEncoder, PEMWriter

hash

public String hash()
            throws IOException
Returns the SHA1 hash for the DER encoded CSR.

Returns:
String containing the SHA1 hash for the DER encoding.
Throws:
IOException - if construction of hash fails

bytetoString

private String bytetoString(byte[] bytes)
returns a String representation of the given byte[] array. In Java 1.5 and higher this can be done using String.format(java.lang.String, java.lang.Object...)("%02x",bytes[i]).

Parameters:
bytes - byte[] array to convert
Returns:
String representing the byte[] array


nl.nikhef.slcshttps Mischa Sallé - msalle(AT)nikhef.nl