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
-
RSAPrivateKey(ASN1Object)
- Creates a new private key from an ASN1Object.
-
RSAPrivateKey(BigInteger, BigInteger, BigInteger)
- Creates a private key from the given values.
-
RSAPrivateKey(BigInteger, BigInteger, BigInteger, BigInteger, BigInteger, BigInteger, BigInteger, BigInteger)
- Creates a private key from the given values.
-
RSAPrivateKey(byte[])
- Creates a new private key from a DER or PEM encoded ASN.1 datastructure.
-
RSAPrivateKey(String)
- Creates a new private key from a DER or PEM file.
-
crypt(BigInteger)
- Encrypt or decrypt a BigInteger using the private key.This method
uses a fast algorithm based on the chinese remainder theorem.
-
decrypt(String)
- Decrypt an encrypted PrivateKeyInfo (PKCS#5 and PKCS#8).
-
encrypt(String, AlgorithmID)
- Encrypt the PrivateKeyInfo data structure (PKCS#5 and PKCS#8).
-
getAlgorithm()
- Returns the name of the algorithm: RSA.
-
getCodingFormat()
- Returns the coding format.
-
getEncoded()
- Returns the encoded private key:
The ASN.1 type is "SubjectPublicKeyInfo" and the coding is DER.
-
getEncryptionAlgorithm()
- Returns the encryption algorithm or null, if this RSAPrivateKey
is not encrypted.
-
getExponent()
- Returns the private exponent of this private key.
-
getFormat()
- Returns the name of the encoding format: X.509.
-
getModulus()
- Returns the modulus of this private key.
-
getPublicExponent()
- Returns the public exponent of this private key.
-
getPublicKey()
- Returns the public parts of this private key.
-
saveToFile(String)
- Saves this private key into a file.
-
setCodingFormat(int)
- Sets the format for saveToFile(), getEncoded() and toByteArray().
-
toString()
- Returns a string that represents the contents of this private key.
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
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
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:
- RSAPrivateKey
- PrivateKeyInfo
- EncryptedPrivateKeyInfo
- Parameters:
- pk - the private key
- Throws: InvalidKeyException
- if something is wrong with the key encoding
RSAPrivateKey
public RSAPrivateKey(ASN1Object obj) throws InvalidKeyException
- Creates a new private key from an ASN1Object.
The ASN1Object can be of the following type:
- RSAPrivateKey
- PrivateKeyInfo
- EncryptedPrivateKeyInfo
- Parameters:
- obj - the private key as ASN1Object
- Throws: InvalidKeyException
- if something is wrong with the key encoding
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
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
decrypt
public void decrypt(String password)
- Decrypt an encrypted PrivateKeyInfo (PKCS#5 and PKCS#8).
- Parameters:
- password - the password to decrypt the key
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
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
getAlgorithm
public String getAlgorithm()
- Returns the name of the algorithm: RSA.
- Returns:
- the name of the algorithm
getFormat
public String getFormat()
- Returns the name of the encoding format: X.509.
- Returns:
- the name of the encoding format
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
setCodingFormat
public void setCodingFormat(int format)
- Sets the format for saveToFile(), getEncoded() and toByteArray().
- Parameters:
- format - ASN1.PEM or ASN1.DER
getCodingFormat
public int getCodingFormat()
- Returns the coding format.
- Parameters:
- format - ASN1.PEM or ASN1.DER
getPublicKey
public PublicKey getPublicKey()
- Returns the public parts of this private key.
- Returns:
- the public key part of this private key
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
getPublicExponent
public BigInteger getPublicExponent()
- Returns the public exponent of this private key.
- Returns:
- the public exponent of the private key.
getModulus
public BigInteger getModulus()
- Returns the modulus of this private key.
- Returns:
- the public modulus of the private key.
- Overrides:
- getModulus in class RSAKey
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
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