All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class is.hi.logir.cryptonite.RSAKey

java.lang.Object
   |
   +----is.hi.logir.cryptonite.Cryptonite
           |
           +----is.hi.logir.cryptonite.K
                   |
                   +----is.hi.logir.cryptonite.RSAKey

public class RSAKey
extends K
implements CipherKey, SignatureKey
The RSA algorithm is probably the best known and most widely used public key algorithm. Breaking one RSA key is believed to be as difficult as factoring the large integer that comprises the key, and there is no known way to do this in a reasonable time. Therefore RSA should be about as secure as anything if you keep your keys long. 1024 bits should be more than enough in most cases, but the truly paranoid may want to use up to 4096 bit keys.

Each RSA key is a pair (r,n) of integers and matches another key (s,n). If P is a block of plain data represented as an integer smaller than n, then it can be encrypted with the transformation:

E = (P^r) mod n
which has the inverse transformation:
P = (E^s) mod n

The key owner will keep one key secret and publish the other as widely as possible. This allows anyone who gets hold of the public key to encrypt data which can only be decrypted with the corresponding private key.

Data that is encrypted with a private key can similarly only be decrypted with the corresponding public key. This is useful for digital signatures.

When P is created from an array of bytes, it will correspond to as many bytes of plain data as the bytes needed to store n, less one.

Each chunk of data encrypted with RSAKey has as many bytes as the key modulo. however, the plain data it encodes has one less byte.

The CDS for the RSAKey class is RSAKey(r,n,pub) for a public key or RSAKey(r,n,pri) for a private key. In both cases r and n are hexadecimal numbers.

Author:
Logi Ragnarsson (logir@hi.is)
See Also:
Signature, fromString

Constructor Index

 o RSAKey(BigInteger, BigInteger, boolean)
Create a new RSA key (r,n).
 o RSAKey(String)
Called by Cryptonite.fromString(String) .

Method Index

 o cipherBlockSize()
Returns the size of the blocks that can be decrypted in one call to decrypt().
 o createKeys(BigInteger, BigInteger, BigInteger)
Create a KeyPair object holding objects for the public RSA key (r,n) and the private RSA key (s,n).
 o createKeys(int)
Create a pair of public/private keys.
 o decrypt(byte[], int, byte[], int)
Decrypt a single block from source, starting at i, and write it to dest, starting at j.
 o encrypt(byte[], int, byte[], int)
Encrypt a single block from source, starting at i, and write it to dest, starting at j.
 o equals(Object)
Reutns trud iff this and key are equivalent.
 o getAlgorithm()
Return "RSA"
 o getSize()
Return the size of the key modulo in bits.
 o isPrivate()
Return true iff this is a private key.
 o matches(Key)
Returns true if this and key are a matched pair of public/private keys.
 o matches(Signature, Fingerprint)
Return true iff s is a signature for fp created with this key in the case of a symmetric key, or the other key in the pair in the case of an asymmetric key.
 o plainBlockSize()
Returns the size of the blocks that can be encrypted in one call to encrypt().
 o sign(Fingerprint)
Create a signature for the fingerprint fp.
 o signatureSize()
Returns the length of the signature in bytes.
 o signBlockSize()
Returns the maximum size in bytes of the fingerprint that can be signed.
 o toString()
Return a CDS for this key.

Constructors

 o RSAKey
 public RSAKey(BigInteger r,
               BigInteger n,
               boolean pri)
Create a new RSA key (r,n). It is a private key if pri is true.

 o RSAKey
 public RSAKey(String arg) throws InvalidCDSException
Called by Cryptonite.fromString(String) .

Throws: InvalidCDSException
if the CDS is in some way malformed.
See Also:
fromString

Methods

 o createKeys
 public static KeyPair createKeys(int bitLength)
Create a pair of public/private keys. The key modulo will be bitLength or bitLength-1 bits.

 o createKeys
 public static KeyPair createKeys(BigInteger r,
                                  BigInteger s,
                                  BigInteger n) throws KeyException
Create a KeyPair object holding objects for the public RSA key (r,n) and the private RSA key (s,n).

Throws: KeyException
if (r,s,n) does not describe a valid RSA key.
 o getSize
 public int getSize()
Return the size of the key modulo in bits.

Overrides:
getSize in class K
 o getAlgorithm
 public String getAlgorithm()
Return "RSA"

Overrides:
getAlgorithm in class K
 o isPrivate
 public boolean isPrivate()
Return true iff this is a private key.

Overrides:
isPrivate in class K
 o toString
 public String toString()
Return a CDS for this key.

Overrides:
toString in class Object
See Also:
fromString
 o equals
 public boolean equals(Object key)
Reutns trud iff this and key are equivalent.

Overrides:
equals in class Object
 o matches
 public final boolean matches(Key key)
Returns true if this and key are a matched pair of public/private keys.

Overrides:
matches in class K
 o plainBlockSize
 public int plainBlockSize()
Returns the size of the blocks that can be encrypted in one call to encrypt(). For RSA keys this depends on the size of the key.

 o cipherBlockSize
 public int cipherBlockSize()
Returns the size of the blocks that can be decrypted in one call to decrypt(). For RSA keys this depends on the size of the key.

 o encrypt
 public final void encrypt(byte source[],
                           int i,
                           byte dest[],
                           int j)
Encrypt a single block from source, starting at i, and write it to dest, starting at j.

 o decrypt
 public void decrypt(byte source[],
                     int i,
                     byte dest[],
                     int j)
Decrypt a single block from source, starting at i, and write it to dest, starting at j.

 o signBlockSize
 public int signBlockSize()
Returns the maximum size in bytes of the fingerprint that can be signed.

 o signatureSize
 public int signatureSize()
Returns the length of the signature in bytes.

 o sign
 public Signature sign(Fingerprint fp) throws KeyException
Create a signature for the fingerprint fp.

Throws: KeyException
if the key modulus is shorter than the signature.
 o matches
 public boolean matches(Signature s,
                        Fingerprint fp)
Return true iff s is a signature for fp created with this key in the case of a symmetric key, or the other key in the pair in the case of an asymmetric key.


All Packages  Class Hierarchy  This Package  Previous  Next  Index