|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--iaik.x509.PublicKeyInfo
|
+--iaik.security.rsa.RSAPublicKey
This class implements a RSA public key and supports ASN.1 encoding.
This class extends iaik.x509.PublicKeyInfo for supporting RSA public
keys to be used within X.509 certificates. This class implements
the java.security.interfaces.RSAPublicKey interface for providing the
functionality of a public key, as used for data encrypting or signature verifying based
on the RSA algorithm.
PKCS#1 describes a X.509/PEM
compatible syntax for RSA public keys to be used in certificates. The corresponding ASN.1
type RSAPublicKey is defined as ASN.1 SEQUENCE:
RSAPublicKey ::= SEQUENCE {
modulus INTEGER, -- n
publicExponent INTEGER -- e }
An application wishing to create a RSAPublicKey to be used for, e.g. data encryption or
signature verifying 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 RSAPublicKey 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();
RSAPublicKey rsa_pub_key = (RSAPublicKey)key_pair.getPublic();
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.
PublicKeyInfo,
RSAPublicKey,
KeyPairGenerator,
KeyPair,
iaik.pkcs.pkcs1.RSACipher,
RSAKey,
RSAPrivateKey,
RSAKeyPairGenerator,
RSAKeyFactory, Serialized Form| Fields inherited from class iaik.x509.PublicKeyInfo |
public_key_algorithm |
| Fields inherited from interface java.security.PublicKey |
serialVersionUID |
| Fields inherited from interface java.security.Key |
serialVersionUID |
| Constructor Summary | |
RSAPublicKey(ASN1Object obj)
Creates a new RSAPublicKey from the given ASN.1 data structure representing a RSAPublicKey or PublicKeyInfo. |
|
RSAPublicKey(java.math.BigInteger modulus,
java.math.BigInteger publicExponent)
Creates a new RSAPublicKey with given values for the modulus n and the
public exponent e. |
|
RSAPublicKey(byte[] pk)
Creates a new RSAPublicKey from the given DER encoded byte array. |
|
RSAPublicKey(java.io.InputStream is)
Creates a new RSAPublicKey from an InputStream. |
|
RSAPublicKey(RSAPublicKey key)
Creates a new RSAPublicKey from the given RSAPublicKey representing modulus n and public exponent e. |
|
RSAPublicKey(RSAPublicKeySpec keySpec)
Creates a new RSAPublicKey from the given RSAPublicKeySpec representing modulus n and public exponent e. |
|
| Method Summary | |
java.lang.Object |
clone()
|
java.math.BigInteger |
crypt(java.math.BigInteger message)
Uses the public key to encrypt or decrypt a message. |
protected void |
decode(byte[] publicKey)
Decodes a RSAPublicKey, encoded in DER format (PKCS#1). |
protected byte[] |
encode()
Returns this RSA public key as DER encoded ASN.1 object (PKCS#1). |
boolean |
equals(java.lang.Object obj)
Compares this public key to another public key. |
java.lang.String |
getAlgorithm()
Returns the name of the appertaining algorithm. |
byte[] |
getFingerprint()
Returns the fingerprint of this RSA public key. |
java.math.BigInteger |
getModulus()
Returns the modulus of the public key. |
java.math.BigInteger |
getPublicExponent()
Returns the public exponent of the public key. |
int |
hashCode()
Returns a hash code for this object. |
java.lang.String |
toString()
Returns a string that represents the contents of this RSA public key. |
| Methods inherited from class iaik.x509.PublicKeyInfo |
createPublicKeyInfo,
decode,
getEncoded,
getFormat,
getPublicKey,
getPublicKey,
toASN1Object,
writeTo |
| Methods inherited from class java.lang.Object |
finalize,
getClass,
notify,
notifyAll,
wait,
wait,
wait |
| Constructor Detail |
public RSAPublicKey(java.math.BigInteger modulus,
java.math.BigInteger publicExponent)
n and the
public exponent e.modulus - the modulus of the keypublicExponent - the public exponent of the keypublic RSAPublicKey(RSAPublicKeySpec keySpec)
n and public exponent e.keySpec - the RSAPublicKeySpec representing modulus n
and public exponent epublic RSAPublicKey(RSAPublicKey key)
n and public exponent e.key - the RSAPublicKey representing modulus n
and public exponent e
public RSAPublicKey(byte[] pk)
throws InvalidKeyException
This constructor may be used for parsing an already exisiting
RSAPublicKey object, supplied as DER encoded
byte array, which may have been created by calling the
encode method.
the - byte array holding the DER encoded public key ASN.1 data structure
public RSAPublicKey(ASN1Object obj)
throws InvalidKeyException
obj - the public key ASN.1 structure
public RSAPublicKey(java.io.InputStream is)
throws java.io.IOException,
InvalidKeyException
is - an input stream with the data to be read to initialize the public key| Method Detail |
protected void decode(byte[] publicKey)
throws InvalidKeyException
From the given DER encoded byte array an ASN.1 object is created and parsed for
modulus n and public exponent e.
publicKey - the public key as DER encoded ASN.1 objectprotected byte[] encode()
public java.math.BigInteger crypt(java.math.BigInteger message)
message - the message to en/decrypt as BigIntegerpublic java.lang.String getAlgorithm()
public java.math.BigInteger getPublicExponent()
public java.math.BigInteger getModulus()
public byte[] getFingerprint()
public int hashCode()
public java.lang.String toString()
public boolean equals(java.lang.Object obj)
public java.lang.Object clone()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||