|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--iaik.pkcs.pkcs8.PrivateKeyInfo
|
+--iaik.security.rsa.RSAPrivateKey
This class implements an RSA private key and supports ASN.1 encoding.
This class extends iaik.pkcs.pkcs8.PrivateKeyInfo for supporting the
PKCS#8 Private Key Information Standard for RSA private keys. This class implements
the java.security.interfaces.RSAPrivateKeyCrt interface for providing the
functionality of a private key, as used for data decrypting or digital signing based
on the RSA algorithm. This class implements the RSAPrivateKeyCrt
interface for using the Chinese Remainder Theorem to speed up private key
operations by extending the standard RSA private key components modulus
n and private exponent d according to
PKCS#1:
RSAPrivateKey ::= SEQUENCE {
version Version, -- a INTEGER version number; 0 for this standard
modulus INTEGER, -- n
publicExponent INTEGER, -- e
privateExponent INTEGER, -- d
prime1 INTEGER, -- primeP (p) (first prime factor of n)
prime2 INTEGER, -- primeQ (q) (second prime factor of n)
exponent1 INTEGER, -- primeExponentP: d mod (p - 1)
exponent2 INTEGER, -- primeExponentQ: d mod (q - 1)
crtCoefficient INTEGER -- Chinese Remainder Theorem ((inverse of q) mod p) }
An application wishing to create a RSAPrivateKey to be used for, e.g. data decryption or
digital signing with the RSA algorithm, uses a proper getInstance method of the
java.security.KeyPairGenerator class, which subsequently maybe casted to
RSAKeyPairGenerator for performing an algorithm-specific initialization with
proper RSA parameters. If an algorithm-specific initialization is not required, the cast
to RSAKeyPairGenerator can be omitted.
Generally four steps have to be performed for creating a RSAPrivateKey by using a proper KeyPairGenerator:
KeyPairGenerator has to be instantiated thereby specifying
the applicationīs intention to create keys for use within the RSA algorithm:
KeyPairGenerator key_gen = KeyPairGenerator.getInstance("RSA");
initialize method. For initializing the generator to create keys with
a modulus length of, e.g., 512 bits, this can be explicitly specified (when not
initializing the generator explicitly, per default the modulus length is set to
1024 bits):
key_gen.initialize(512);
generateKeyPair():
KeyPair key_pair = key_gen.generateKeyPair();
RSAPrivateKey rsa_priv_key = (RSAPrivateKey)key_pair.getPrivate();
For performing an algorithm-specific initialization with particular RSA parameters (e.g. using a particular public exponent e), an explicit cast of the KeyPairGenerator will be necessary for obtaining a specific RSAKeyPairGenerator to be initialized with the desired RSA parameters:
(whereRSAKeyPairGenerator rsa_key_gen = (RSAKeyPairGenerator)key_gen; rsa_key_gen.initialize(512, pub_exponent, sec_random);
sec_random denotes some random seed)
Guidelines on how to create some key using a KeyPairGenerator can be found in http://java.sun.com/products/JDK/1.2/docs/guide/security/CryptoSpec.html.
PrivateKeyInfo,
RSAPrivateCrtKey,
KeyPairGenerator,
KeyPair,
iaik.pkcs.pkcs1.RSACipher,
RSAKey,
RSAPublicKey,
RSAKeyPairGenerator,
RSAKeyFactory, Serialized Form| Fields inherited from class iaik.pkcs.pkcs8.PrivateKeyInfo |
private_key_algorithm,
private_key_info |
| Fields inherited from interface java.security.PrivateKey |
serialVersionUID |
| Fields inherited from interface java.security.Key |
serialVersionUID |
| Constructor Summary | |
protected |
RSAPrivateKey()
Default constructor. |
|
RSAPrivateKey(ASN1Object obj)
Creates a new private key from an ASN1Object. |
|
RSAPrivateKey(java.math.BigInteger modulus,
java.math.BigInteger privateExponent)
Creates a new RSAPrivate key from given modulus and private exponent. |
|
RSAPrivateKey(java.math.BigInteger modulus,
java.math.BigInteger publicExponent,
java.math.BigInteger privateExponent,
java.math.BigInteger primeP,
java.math.BigInteger primeQ,
java.math.BigInteger primeExponentP,
java.math.BigInteger primeExponentQ,
java.math.BigInteger crtCoefficient)
Creates a RSAPrivateKey from the given values. |
|
RSAPrivateKey(byte[] pk)
Creates a new RSAPrivateKey from a DER encoded ASN.1 data structure. |
|
RSAPrivateKey(java.io.InputStream is)
Creates a new RSAPrivateKey from an InputStream. |
|
RSAPrivateKey(RSAPrivateKey key)
Creates a new RSAPrivateKey from a RSAPrivateKey or RSAPrivateKeyCrt. |
|
RSAPrivateKey(RSAPrivateKeySpec keySpec)
Creates a new RSAPrivateKey from a RSAPrivateKeySpec or RSAPrivateKeyCrtSpec. |
| Method Summary | |
java.lang.Object |
clone()
|
java.math.BigInteger |
crypt(java.math.BigInteger message)
Encrypts or decrypts a BigInteger using the private key. |
protected void |
decode(byte[] privateKey)
Decodes a DER encoded RSAPrivateKey (PKCS#1). |
protected byte[] |
encode()
Returns this RSA private key as DER encoded byte array (PKCS#1). |
java.lang.String |
getAlgorithm()
Returns the name of the appertaining algorithm. |
java.math.BigInteger |
getCrtCoefficient()
Returns the Chinese Remainder Theorem coefficient of this private key. |
java.math.BigInteger |
getModulus()
Returns the modulus of this private key. |
java.math.BigInteger |
getPrimeExponentP()
Returns the first exponent of this private key. |
java.math.BigInteger |
getPrimeExponentQ()
Returns the second exponent of this private key. |
java.math.BigInteger |
getPrimeP()
Returns the first prime of this private key. |
java.math.BigInteger |
getPrimeQ()
Returns the second prime of this private key. |
java.math.BigInteger |
getPrivateExponent()
Returns the private exponent of this private key. |
java.math.BigInteger |
getPublicExponent()
Returns the public exponent of this private key. |
PublicKey |
getPublicKey()
Returns the public parts (modulus n and public exponent e
of this private key. |
int |
hashCode()
Returns a hash code for this object. |
static RSAPrivateKey |
parse(byte[] privateKey)
This method parses a RSA private key. |
java.lang.String |
toString()
Returns a string that represents the contents of this private key. |
| Methods inherited from class iaik.pkcs.pkcs8.PrivateKeyInfo |
createPrivateKeyInfo,
decode,
equals,
getEncoded,
getFormat,
getPrivateKey,
getPrivateKey,
toASN1Object,
writeTo |
| Methods inherited from class java.lang.Object |
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
| Constructor Detail |
protected RSAPrivateKey()
public RSAPrivateKey(java.math.BigInteger modulus,
java.math.BigInteger privateExponent)
privateExponent - the private exponent emodulus - the modulus n
public RSAPrivateKey(java.math.BigInteger modulus,
java.math.BigInteger publicExponent,
java.math.BigInteger privateExponent,
java.math.BigInteger primeP,
java.math.BigInteger primeQ,
java.math.BigInteger primeExponentP,
java.math.BigInteger primeExponentQ,
java.math.BigInteger crtCoefficient)
modulus - the modulus npublicExponent - the public exponent eprivateExponent - the private exponent dprimeP - first prime factor of the modulusprimeQ - second prime factor of the modulusprimeExponentP - privateExponent mod (primeP-1)primeExponentQ - privateExponent mod (primeQ-1)crtCoefficient - the Chinese Remainder Theorem coefficient
(multiplic inverse of primeP mod primeQ)public RSAPrivateKey(RSAPrivateKeySpec keySpec)
RSAPrivateKeySpec
the Chinese Remainder Theorem would not be considered by only parsing modulus
and private exponent from the given specification and setting the other parameters
to ZERO (0).
RSAPrivateKeyCrtSpec,
all parameters (modulus, public and private exponent, prime factors p and q,
primeExponentP and primeExponentQ, and Chinese Remainder Theorem coefficient) are
parsed from the given specification.keySpec - the key specpublic RSAPrivateKey(RSAPrivateKey key)
RSAPrivateKey
the Chinese Remainder Theorem would not be considered by only parsing modulus
and private exponent from the given specification and setting the other parameters
to ZERO (0).
RSAPrivateKeyCrt,
all parameters (modulus, public and private exponent, prime factors p and q,
primeExponentP and primeExponentQ, and Chinese Remainder Theorem coefficient) are
parsed from the given specification.key - the key
public RSAPrivateKey(byte[] pk)
throws InvalidKeyException
pk - the byte array holding the DER encoded private key ASN.1 data structure
public RSAPrivateKey(ASN1Object obj)
throws InvalidKeyException
obj - the private key as ASN1Object
public RSAPrivateKey(java.io.InputStream is)
throws java.io.IOException,
InvalidKeyException
is - the input stream with the data to be read to initialize the private key| Method Detail |
protected void decode(byte[] privateKey)
throws InvalidKeyException
From the given DER encoded byte array an ASN.1 object is created and parsed for
the RSAPrivateKey parameters according to PKCS#1: version, modulus n,
public and private exponent (e and d),
prime factor primeP of n, prime factor primeQ of n,
primeExponentP (d mod(p-1)), primeExponentQ (d mod(q-1)),
and crtCoefficient, the Chinese Remainder Thereom coefficient q-1 mod p.
privateKey - the RSA private key as DER encoded byte array
public static RSAPrivateKey parse(byte[] privateKey)
throws InvalidKeyException
privateKey - a "RAW" RSA private keypublic java.math.BigInteger crypt(java.math.BigInteger message)
message - the BigInteger message to encrypt or encryptprotected byte[] encode()
public PublicKey getPublicKey()
n and public exponent e
of this private key.public java.math.BigInteger getPrivateExponent()
public java.math.BigInteger getPublicExponent()
public java.math.BigInteger getModulus()
public java.math.BigInteger getPrimeP()
public java.math.BigInteger getPrimeQ()
public java.math.BigInteger getPrimeExponentP()
exponent = privateExponent mod (prime_p-1);
public java.math.BigInteger getPrimeExponentQ()
exponent = privateExponent mod (prime_q-1);
public java.math.BigInteger getCrtCoefficient()
crtCoefficient = multiplic inverse of prime_p mod prime_q;
public java.lang.String getAlgorithm()
public int hashCode()
public java.lang.String toString()
public java.lang.Object clone()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||