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 and write private keys.

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

Constructor Summary
PrivateKeyReader()
           
 
Method Summary
static java.security.PrivateKey backupPKCS8Reader(java.io.BufferedReader reader)
          The backup implementation for reading pkcs#8 private keys until bouncycastle implementation is released.
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)
          Deprecated. Rather use the method with reader argument.
static java.security.PrivateKey read(java.io.BufferedInputStream bin, org.bouncycastle.openssl.PasswordFinder finder)
          Deprecated. use rather the read method with reader input.
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 java.security.PrivateKey read(java.io.BufferedReader reader)
          Reads the private key form the stream that was given in the constructor.
static java.security.PrivateKey read(java.io.BufferedReader reader, org.bouncycastle.openssl.PasswordFinder finder)
          Reads the private key form the stream that was given in the constructor.
static void skipLine(java.io.BufferedInputStream stream)
          Deprecated. do not use, use bufferedReader.readline instead. Scheduled for removal.
 
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
Deprecated. use rather the read method with reader input.

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.BufferedReader reader,
                                            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
Deprecated. Rather use the method with reader argument.

Reads the private key form the stream that was given in the constructor. After the reading, the file mark is advanced 100 chars to avoid reparsing the key. If there is 100 or more chars in the stream before the private key, the next read for certificate, crl, or private key will reread the private key and probably cause problems.

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.BufferedReader reader)
                                     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
Deprecated. do not use, use bufferedReader.readline instead. Scheduled for removal.

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.

backupPKCS8Reader

public static java.security.PrivateKey backupPKCS8Reader(java.io.BufferedReader reader)
                                                  throws java.io.IOException
The backup implementation for reading pkcs#8 private keys until bouncycastle implementation is released.

Parameters:
reader - the reader to read the pem encoded key from.
Returns:
the read private key.
Throws:
java.io.IOException - in case the reading fails.