pk.edu.niit.clarens.util
Class RSAPrivateKeyBlock

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

public class RSAPrivateKeyBlock
extends PEMBlock

This class represents a RSA private key. The private key is created from a string of PEM encoded data, such as a traditional openssl private key stored in a text file. 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
           
 
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
RSAPrivateKeyBlock(java.lang.String data)
          Load a new openssl traditional private key from a string of data.
 
Method Summary
 java.security.cert.Certificate getCertificate()
          Get the certificate from this block.
 java.security.PrivateKey getPrivateKey()
          Get the unencrypted private key structure represented by this block.
 java.security.PrivateKey getPrivateKey(java.lang.String passphrase)
          Get the encrypted private key structure represented by this block.
 
Methods inherited from class pk.edu.niit.clarens.util.PEMBlock
getInstance, getInstance, getPem, getType, getTypeString, load, 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
Constructor Detail

RSAPrivateKeyBlock

public RSAPrivateKeyBlock(java.lang.String data)
                   throws java.security.cert.CertificateException,
                          java.io.IOException
Load a new openssl traditional private key from a string of data. This constructor should not be used unless you are sure that the input source is a private key. 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 key from the PEM data.
java.io.IOException - Thrown if there was a problem decoding the base64 data.
Method Detail

getPrivateKey

public java.security.PrivateKey getPrivateKey()
                                       throws java.security.cert.CertificateException
Get the unencrypted private key structure represented by this block. The private key is extracted from the block data.

Specified by:
getPrivateKey in class PEMBlock
Returns:
The private key structure represented by the block.
Throws:
java.security.cert.CertificateException - Thrown if there was a problem extracting the private key from the block data.

getPrivateKey

public java.security.PrivateKey getPrivateKey(java.lang.String passphrase)
                                       throws java.security.cert.CertificateException
Get the encrypted private key structure represented by this block. Not currently supported.

Specified by:
getPrivateKey in class PEMBlock
Returns:
The private key structure represented by the block.
Throws:
java.security.cert.CertificateException - Thrown if there was a problem extracting the private key from the block data. This can occur if the private key format is unsupported (openssl DSA) or if the private key was encrypted.

getCertificate

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

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