org.glite.security.util
Class PrivateKeyReader

java.lang.Object
  extended by org.glite.security.util.PrivateKeyReader

public class PrivateKeyReader
extends java.lang.Object

This class is used to read a private key.

Author:
Joni Hahkala Created on April 8, 2002, 9:26 PM

Constructor Summary
PrivateKeyReader()
           
 
Method Summary
static byte[] getEncoded(java.security.PrivateKey inKey)
          Return a PKCS1v2 representation of the key.
static java.lang.String getPEM(java.security.PrivateKey inKey)
          Return a PEM formatted PKCS1v2 representation of the key.
static java.security.PrivateKey read(java.io.BufferedInputStream bin)
          Reads the private key form the stream that was given in the constructor.
static java.security.PrivateKey read(java.io.BufferedInputStream bin, org.bouncycastle.openssl.PasswordFinder finder)
          Reads the private key form the stream that was given in the constructor.
static java.security.PrivateKey read(java.io.BufferedInputStream bin, java.lang.String passwd)
          Reads the private key form the stream that was given in the constructor.
static void skipLine(java.io.BufferedInputStream stream)
          Skips to the next line.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrivateKeyReader

public PrivateKeyReader()
Method Detail

read

public static java.security.PrivateKey read(java.io.BufferedInputStream bin,
                                            org.bouncycastle.openssl.PasswordFinder finder)
                                     throws java.io.IOException
Reads the private key form the stream that was given in the constructor. After the reading, the file mark is at the end of the key.

Parameters:
bin - The BufferedInputStream to read the key from.
finder - The password finder class to use for requesting the password.
Returns:
Returns the private key read.
Throws:
java.io.IOException - Thrown if the key reading fails.

read

public static java.security.PrivateKey read(java.io.BufferedInputStream bin)
                                     throws java.io.IOException
Reads the private key form the stream that was given in the constructor. After the reading, the file mark is at the end of the key.

Parameters:
bin - The BufferedInputStream to read the key from.
Returns:
Returns the private key read.
Throws:
java.io.IOException - Thrown if the key reading fails.

read

public static java.security.PrivateKey read(java.io.BufferedInputStream bin,
                                            java.lang.String passwd)
                                     throws java.io.IOException
Reads the private key form the stream that was given in the constructor. After the reading, the file mark is at the end of the key.

Parameters:
bin - The BufferedInputStream to read the key from.
passwd - The password to use to access the private key.
Returns:
Returns the private key read.
Throws:
java.io.IOException - Thrown if the key reading fails.

skipLine

public static void skipLine(java.io.BufferedInputStream stream)
                     throws java.io.IOException
Skips to the next line.

Parameters:
stream - the input stream.
Throws:
java.io.IOException - thrown in case of read error.

getEncoded

public static byte[] getEncoded(java.security.PrivateKey inKey)
Return a PKCS1v2 representation of the key. The sequence returned represents a full PrivateKeyInfo object.

Parameters:
inKey - the key to encode.
Returns:
a PKCS1v2 representation of the key.

getPEM

public static java.lang.String getPEM(java.security.PrivateKey inKey)
Return a PEM formatted PKCS1v2 representation of the key. The sequence returned represents a full PrivateKeyInfo object. Had to re-implement as the other PEM encoders produce wrong version of the key.

Parameters:
inKey - the key to encode.
Returns:
a PEM format PKCS1v2 representation of the key.