All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class IS.hi.logir.cryptonite.RsaKey

java.lang.Object
   |
   +----IS.hi.logir.cryptonite.Key
           |
           +----IS.hi.logir.cryptonite.RsaKey

public final class RsaKey
extends Key
implements Serializable, Fingerprintable
The RSA algorithm is probably the best known and most widely used public key algorithm. Breaking one RSA key is exactly 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.

When the encrypted integer E is converted to a byte array, it will contain as many bytes as are needed to store n. This means that the encrypted data will be slightly larger, by a ratio of (m+1)/m, with m=trunc(log2(n)/8).

Each chunk of data encrypted with RsaKey has as many bytes as the key modulo. However, the encrypted data it contains corresponds to plain data with one less byte.

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

Variable Index

 o n
The RSA key modulo
 o r
The RSA key exponent
 o R
R is the exponent used in all public keys.

Constructor Index

 o RsaKey(BigInteger, BigInteger, String, String)
Create a new RSA key (r,n).

Method Index

 o algorithmName()
Return the name of the algorithm used by this key.
 o blockSize()
Returns a number n, such that least space will be wasted if a mutiple of n bytes is encrypted at once.
 o calcFingerprint()
Return the key's MD5 fingerprint.
 o createKeys(BigInteger, BigInteger, BigInteger, String, String)
Create a KeyPair object holding objects for the public RSA key (r,n) and the private RSA key (s,n).
 o createKeys(int, String, String)
Create a pair of public/private keys.
 o decrypt(Data, Data)
Decrypt the data from source with this key and put the plain data in dest.
 o encrypt(Data, Data)
Encrypt source with this key and put the result in dest.
 o equals(Object)
Return true if the two keys are eqivalent.
 o getSize()
Return the size of the key modulo in bits.
 o matches(Key)
Returns true if this and key are a matched pair of public/private keys.
 o toString()
Return a string representation of this key.

Variables

 o R
 private static final BigInteger R
R is the exponent used in all public keys.

 o r
 private BigInteger r
The RSA key exponent

 o n
 private BigInteger n
The RSA key modulo

Constructors

 o RsaKey
 public RsaKey(BigInteger r,
               BigInteger n,
               String ownerName,
               String ownerMail)
Create a new RSA key (r,n). It will be marked as belonging to ownerName with e-mail address ownerMail.

Methods

 o createKeys
 public static KeyPair createKeys(int bitLength,
                                  String ownerName,
                                  String ownerMail)
Create a pair of public/private keys. The key modulo will be at most bitLength bits in length and not much shorter. It will be marked as belonging to ownerName with e-mail address ownerMail.

 o createKeys
 public static KeyPair createKeys(BigInteger r,
                                  BigInteger s,
                                  BigInteger n,
                                  String ownerName,
                                  String ownerMail) throws KeyException
Create a KeyPair object holding objects for the public RSA key (r,n) and the private RSA key (s,n). They will be marked as belonging to ownerName with e-mail address ownerMail.

 o getSize
 public int getSize()
Return the size of the key modulo in bits.

Overrides:
getSize in class Key
 o calcFingerprint
 protected final Fingerprint calcFingerprint()
Return the key's MD5 fingerprint.

Overrides:
calcFingerprint in class Key
See Also:
MD5State, Fingerprintable
 o algorithmName
 public String algorithmName()
Return the name of the algorithm used by this key.

Overrides:
algorithmName in class Key
 o toString
 public String toString()
Return a string representation of this key.

Overrides:
toString in class Key
 o equals
 public final boolean equals(Object o)
Return true if the two keys are eqivalent.

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 Key
 o blockSize
 public int blockSize()
Returns a number n, such that least space will be wasted if a mutiple of n bytes is encrypted at once.

Overrides:
blockSize in class Key
 o encrypt
 public final void encrypt(Data source,
                           Data dest)
Encrypt source with this key and put the result in dest. The source.buf and dest.buf arrays must be different.

Overrides:
encrypt in class Key
 o decrypt
 public void decrypt(Data source,
                     Data dest)
Decrypt the data from source with this key and put the plain data in dest. The source.buf and dest.buf arrays must be different.

Overrides:
decrypt in class Key

All Packages  Class Hierarchy  This Package  Previous  Next  Index