|
|||||||||
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
,
RSACipher
,
RSAKey
,
RSAPublicKey
,
RSAKeyPairGenerator
,
RSAKeyFactory
, Serialized FormFields inherited from class iaik.pkcs.pkcs8.PrivateKeyInfo |
private_key_algorithm |
Fields inherited from interface java.security.PrivateKey |
serialVersionUID |
Constructor Summary | |
protected |
RSAPrivateKey()
Default constructor. |
|
RSAPrivateKey(ASN1Object obj)
Creates a new private key from an ASN1Object. |
|
RSAPrivateKey(BigInteger modulus,
BigInteger privateExponent)
Creates a new RSAPrivate key from given modulus and private exponent. |
|
RSAPrivateKey(BigInteger modulus,
BigInteger publicExponent,
BigInteger privateExponent,
BigInteger primeP,
BigInteger primeQ,
BigInteger primeExponentP,
BigInteger primeExponentQ,
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(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 | |
BigInteger |
crypt(BigInteger message)
Deprecated. Use iaik.pkcs.pkcs1.RSACipher#rawPrivateRSA instead. |
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). |
String |
getAlgorithm()
Returns the name of the appertaining algorithm. |
BigInteger |
getCrtCoefficient()
Returns the Chinese Remainder Theorem coefficient of this private key. |
BigInteger |
getModulus()
Returns the modulus of this private key. |
BigInteger |
getPrimeExponentP()
Returns the first exponent of this private key. |
BigInteger |
getPrimeExponentQ()
Returns the second exponent of this private key. |
BigInteger |
getPrimeP()
Returns the first prime of this private key. |
BigInteger |
getPrimeQ()
Returns the second prime of this private key. |
BigInteger |
getPrivateExponent()
Returns the private exponent of this private key. |
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. |
String |
toString()
Returns a string that represents the contents of this private key. |
Methods inherited from class iaik.pkcs.pkcs8.PrivateKeyInfo |
clone, createPrivateKeyInfo, decode, equals, getEncoded, getFormat, getPrivateKey, getPrivateKey, toASN1Object, writeTo |
Methods inherited from class java.lang.Object |
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.security.Key |
getEncoded, getFormat |
Constructor Detail |
protected RSAPrivateKey()
public RSAPrivateKey(BigInteger modulus, BigInteger privateExponent)
privateExponent
- the private exponent e
modulus
- the modulus n
public RSAPrivateKey(BigInteger modulus, BigInteger publicExponent, BigInteger privateExponent, BigInteger primeP, BigInteger primeQ, BigInteger primeExponentP, BigInteger primeExponentQ, BigInteger crtCoefficient)
modulus
- the modulus n
publicExponent
- the public exponent e
privateExponent
- the private exponent d
primeP
- 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 keypublic RSAPrivateKey(byte[] pk) throws InvalidKeyException
This constructor may be used for parsing an already exisiting
RSA private key, wrapped into a PKCS#8 PrivateKeyInfo
that is supplied as DER encoded byte array.
the
- byte array holding the DER encoded private key infoInvalidKeyException
- if something is wrong with the key encodingpublic RSAPrivateKey(ASN1Object obj) throws InvalidKeyException
PrivateKeyInfo
holding the RSA private key.obj
- the private key as ASN1ObjectInvalidKeyException
- if something is wrong with the key encodingpublic RSAPrivateKey(InputStream is) throws IOException, InvalidKeyException
This constructor may be used for parsing an already exisiting
RSA private key, wrapped into a PKCS#8 PrivateKeyInfo
that is supplied as DER encoded byte array.
is
- the input stream with the data to be read to initialize the private keyIOException
- if an I/O error occursInvalidKeyException
- if something is wrong with the key encodingMethod 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.
This method is protected and typically will not be used by an application. Rather
it is used by the parent PKCS#8 PrivateKeyInfo
class for decoding the inherent RSA private key.
decode
in class PrivateKeyInfo
privateKey
- the RSA private key as DER encoded byte arrayInvalidKeyException
- if the given key is not a RSA private keypublic static RSAPrivateKey parse(byte[] privateKey) throws InvalidKeyException
privateKey
- a "RAW" RSA private keyInvalidKeyException
- if the given key is not a RSA private keypublic BigInteger crypt(BigInteger message)
message
- the BigInteger message to encrypt or encryptprotected byte[] encode()
This method is protected and typically will not be used by an application. Rather
it is used by the parent PKCS#8 PrivateKeyInfo
class for encoding the inherent RSA private key.
encode
in class PrivateKeyInfo
public PublicKey getPublicKey()
n
and public exponent e
of this private key.public BigInteger getPrivateExponent()
getPrivateExponent
in interface RSAPrivateKey
public BigInteger getPublicExponent()
getPublicExponent
in interface RSAPrivateCrtKey
public BigInteger getModulus()
getModulus
in interface RSAKey
public BigInteger getPrimeP()
getPrimeP
in interface RSAPrivateCrtKey
public BigInteger getPrimeQ()
getPrimeQ
in interface RSAPrivateCrtKey
public BigInteger getPrimeExponentP()
exponent = privateExponent mod (prime_p-1);
getPrimeExponentP
in interface RSAPrivateCrtKey
public BigInteger getPrimeExponentQ()
exponent = privateExponent mod (prime_q-1);
getPrimeExponentQ
in interface RSAPrivateCrtKey
public BigInteger getCrtCoefficient()
crtCoefficient = multiplic inverse of prime_p mod prime_q;
getCrtCoefficient
in interface RSAPrivateCrtKey
public String getAlgorithm()
getAlgorithm
in interface Key
getAlgorithm
in class PrivateKeyInfo
public int hashCode()
hashCode
in class PrivateKeyInfo
public String toString()
toString
in class PrivateKeyInfo
|
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). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |