iaik.utils
Class SSLeayPrivateKey

java.lang.Object
  |
  +--iaik.utils.SSLeayPrivateKey
All Implemented Interfaces:
Key, PrivateKey, Serializable

public class SSLeayPrivateKey
extends Object
implements PrivateKey

The SSLeayPrivateKey is used to read/write and decrypt/encrypt private keys created with SSLeay.

Parts based on code by Stephan Spitz / TUEV Sueddeutschland.

Version:
File Revision 17
See Also:
Serialized Form

Fields inherited from interface java.security.PrivateKey
serialVersionUID
 
Constructor Summary
SSLeayPrivateKey(InputStream is)
          Reads a private key created by SSLeay from the specified file.
SSLeayPrivateKey(PrivateKey privateKey)
          This constructor gets a private key object to convert it into the OpenSSL format.
SSLeayPrivateKey(String fileName)
          Reads a private key created by SSLeay from the specified file.
 
Method Summary
 void decrypt(String password)
          Decrypts this private key.
 void encrypt(String password, String encryptionAlg, byte[] iv)
          Encrypts this private key.
 String getAlgorithm()
          Returns the symmetric encryption algorithm used to protect this private key.
 byte[] getEncoded()
          This method returns the DER encoded OpenSSL key which has PKCS#1 format.
 String getFormat()
          Returns the format used to encode the key or null if the key does not support encoding.
 PrivateKey getPrivateKey()
          Returns the included private key.
 boolean isEncrypted()
          Test if this private key is encrypted.
 void writeTo(OutputStream out)
          Write the SSLeayPrivateKey to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SSLeayPrivateKey

public SSLeayPrivateKey(PrivateKey privateKey)
                 throws InvalidKeyException,
                        CodingException
This constructor gets a private key object to convert it into the OpenSSL format. The object should be an instance of RSAPrivateKey, DSAPrivateKey, or DHPrivateKey.
Parameters:
privaeKey - the key object
Throws:
InvalidKeyException - if the key is invalid
CodingException - if the key cannot be encoded

SSLeayPrivateKey

public SSLeayPrivateKey(String fileName)
                 throws IOException,
                        InvalidKeyException
Reads a private key created by SSLeay from the specified file.
Parameters:
fileName - the name of the file containing the private key
Throws:
IOException - if an error occurs during reading the key
InvalidKeyException - if the key can not be parsed

SSLeayPrivateKey

public SSLeayPrivateKey(InputStream is)
                 throws IOException,
                        InvalidKeyException
Reads a private key created by SSLeay from the specified file.
Parameters:
is - an input stream containing the private key
Throws:
IOException - if an error occurs during reading the key
InvalidKeyException - if the key can not be parsed
Method Detail

isEncrypted

public boolean isEncrypted()
Test if this private key is encrypted.
Returns:
true if this private key is encrypted

getPrivateKey

public PrivateKey getPrivateKey()
                         throws InvalidKeyException
Returns the included private key.
Returns:
the private key
Throws:
InvalidKeyException - if an error occurs during parsing this private key or the is not decrypted yet

decrypt

public void decrypt(String password)
             throws InvalidKeyException
Decrypts this private key. Does nothing if the key is not encrypted.
Parameters:
password - the password to decrypt the private key

encrypt

public void encrypt(String password,
                    String encryptionAlg,
                    byte[] iv)
             throws InvalidKeyException,
                    NoSuchAlgorithmException,
                    GeneralSecurityException
Encrypts this private key. Does nothing if the key is already encrypted. The algorithm should be one of DES-CBC, DES-EDE3-CBC (default if null), or IDEA/CBC/PKCS5Padding. If iv is null, a new value is generated
Parameters:
password - the password to decrypt the private key
encryptionalg - the algorithm used to encrypt the private key

getAlgorithm

public String getAlgorithm()
Returns the symmetric encryption algorithm used to protect this private key.
Specified by:
getAlgorithm in interface Key
Returns:
the encryption algorithm or null if the private key is not encrypted

getEncoded

public byte[] getEncoded()
This method returns the DER encoded OpenSSL key which has PKCS#1 format.
Specified by:
getEncoded in interface Key
Returns:
the encoded OpenSSL key

getFormat

public String getFormat()
Returns the format used to encode the key or null if the key does not support encoding.
Specified by:
getFormat in interface Key
Returns:
the string "SSLeay"

writeTo

public void writeTo(OutputStream out)
             throws IOException
Write the SSLeayPrivateKey to a file.

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK