All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class iaik.security.rsa.RSAPrivateKey

java.lang.Object
   |
   +----iaik.security.rsa.RSAKey
           |
           +----iaik.security.rsa.RSAPrivateKey

public class RSAPrivateKey
extends RSAKey
implements RSAPrivateKey, Serializable
This class implements an RSA private key.

See Also:
Key, PublicKey, PrivateKey, RSAPublicKey

Constructor Index

 o RSAPrivateKey(ASN1Object)
Creates a new private key from an ASN1Object.
 o RSAPrivateKey(BigInteger, BigInteger, BigInteger)
Creates a private key from the given values.
 o RSAPrivateKey(BigInteger, BigInteger, BigInteger, BigInteger, BigInteger, BigInteger, BigInteger, BigInteger)
Creates a private key from the given values.
 o RSAPrivateKey(byte[])
Creates a new private key from a DER or PEM encoded ASN.1 datastructure.
 o RSAPrivateKey(String)
Creates a new private key from a DER or PEM file.

Method Index

 o crypt(BigInteger)
Encrypt or decrypt a BigInteger using the private key.This method uses a fast algorithm based on the chinese remainder theorem.
 o decrypt(String)
Decrypt an encrypted PrivateKeyInfo (PKCS#5 and PKCS#8).
 o encrypt(String, AlgorithmID)
Encrypt the PrivateKeyInfo data structure (PKCS#5 and PKCS#8).
 o getAlgorithm()
Returns the name of the algorithm: RSA.
 o getCodingFormat()
Returns the coding format.
 o getEncoded()
Returns the encoded private key: The ASN.1 type is "SubjectPublicKeyInfo" and the coding is DER.
 o getEncryptionAlgorithm()
Returns the encryption algorithm or null, if this RSAPrivateKey is not encrypted.
 o getExponent()
Returns the private exponent of this private key.
 o getFormat()
Returns the name of the encoding format: X.509.
 o getModulus()
Returns the modulus of this private key.
 o getPublicExponent()
Returns the public exponent of this private key.
 o getPublicKey()
Returns the public parts of this private key.
 o saveToFile(String)
Saves this private key into a file.
 o setCodingFormat(int)
Sets the format for saveToFile(), getEncoded() and toByteArray().
 o toString()
Returns a string that represents the contents of this private key.

Constructors

 o RSAPrivateKey
 public RSAPrivateKey(BigInteger privateExponent,
                      BigInteger publicExponent,
                      BigInteger modulus)
Creates a private key from the given values.

Parameters:
privateExponent - the private exponent
publicExponent - the public exponent
modulus - the modulus
 o RSAPrivateKey
 public RSAPrivateKey(BigInteger prime1,
                      BigInteger prime2,
                      BigInteger exponent1,
                      BigInteger exponent2,
                      BigInteger coefficient,
                      BigInteger privateExponent,
                      BigInteger publicExponent,
                      BigInteger modulus)
Creates a private key from the given values.

Parameters:
prime1 - first prime factor of the modulus
prime2 - second prime factor of the modulus
exponent1 - privateExponent mod (prime1-1)
exponent2 - privateExponent mod (prime2-1)
coefficient - multiplic inverse of prime1 mod prime2
privateExponent - the private exponent
publicExponent - the public exponent
modulus - the modulus
 o RSAPrivateKey
 public RSAPrivateKey(byte pk[]) throws InvalidKeyException
Creates a new private key from a DER or PEM encoded ASN.1 datastructure. The following ASN.1 types are suported for the private key:

Parameters:
pk - the private key
Throws: InvalidKeyException
if something is wrong with the key encoding
 o RSAPrivateKey
 public RSAPrivateKey(ASN1Object obj) throws InvalidKeyException
Creates a new private key from an ASN1Object. The ASN1Object can be of the following type:

Parameters:
obj - the private key as ASN1Object
Throws: InvalidKeyException
if something is wrong with the key encoding
 o RSAPrivateKey
 public RSAPrivateKey(String fileName) throws IOException, InvalidKeyException
Creates a new private key from a DER or PEM file.

Parameters:
fileName - the key file name
Throws: InvalidKeyException
if something is wrong with the key encoding
Throws: IOException
if something is wrong with the file

Methods

 o crypt
 public BigInteger crypt(BigInteger message)
Encrypt or decrypt a BigInteger using the private key.This method uses a fast algorithm based on the chinese remainder theorem.

Parameters:
message - the BigInteger to encrypt or encrypt
Returns:
the encrypted or decrypted message
Overrides:
crypt in class RSAKey
 o decrypt
 public void decrypt(String password)
Decrypt an encrypted PrivateKeyInfo (PKCS#5 and PKCS#8).

Parameters:
password - the password to decrypt the key
 o encrypt
 public void encrypt(String password,
                     AlgorithmID encAlgorithm) throws NoSuchAlgorithmException
Encrypt the PrivateKeyInfo data structure (PKCS#5 and PKCS#8).

Parameters:
password - the password to use
encAlgorithm - the AlgorithmID of the encryption algorithm
Throws: NoSuchAlgorithmException
if there is no implementation for the specified algorithm
 o getEncoded
 public byte[] getEncoded()
Returns the encoded private key: The ASN.1 type is "SubjectPublicKeyInfo" and the coding is DER.

Returns:
the private key as a DER encoded ASN.1 datastructure
 o getAlgorithm
 public String getAlgorithm()
Returns the name of the algorithm: RSA.

Returns:
the name of the algorithm
 o getFormat
 public String getFormat()
Returns the name of the encoding format: X.509.

Returns:
the name of the encoding format
 o saveToFile
 public void saveToFile(String fileName) throws IOException
Saves this private key into a file.

Parameters:
fileName - the name of the file
Throws: IOException
if an error occurs during saving the file
 o setCodingFormat
 public void setCodingFormat(int format)
Sets the format for saveToFile(), getEncoded() and toByteArray().

Parameters:
format - ASN1.PEM or ASN1.DER
 o getCodingFormat
 public int getCodingFormat()
Returns the coding format.

Parameters:
format - ASN1.PEM or ASN1.DER
 o getPublicKey
 public PublicKey getPublicKey()
Returns the public parts of this private key.

Returns:
the public key part of this private key
 o getExponent
 public BigInteger getExponent()
Returns the private exponent of this private key.

Returns:
the private exponent of the private key.
Overrides:
getExponent in class RSAKey
 o getPublicExponent
 public BigInteger getPublicExponent()
Returns the public exponent of this private key.

Returns:
the public exponent of the private key.
 o getModulus
 public BigInteger getModulus()
Returns the modulus of this private key.

Returns:
the public modulus of the private key.
Overrides:
getModulus in class RSAKey
 o getEncryptionAlgorithm
 public AlgorithmID getEncryptionAlgorithm()
Returns the encryption algorithm or null, if this RSAPrivateKey is not encrypted.

Returns:
the signature algorithm used to sign this certificate
 o toString
 public String toString()
Returns a string that represents the contents of this private key.

Returns:
the string representation
Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index