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
-
RSAKey(BigInteger, BigInteger, boolean)
- Create a new RSA key
(r,n)
.
-
RSAKey(String)
- Called by
Cryptonite.fromString(String)
.
-
cipherBlockSize()
- Returns the size of the blocks that can be decrypted in one call
to decrypt().
-
createKeys(BigInteger, BigInteger, BigInteger)
- Create a KeyPair object holding objects for the public RSA key
(r,n)
and the private RSA key (s,n).
-
createKeys(int)
- Create a pair of public/private keys.
-
decrypt(byte[], int, byte[], int)
- Decrypt a single block from
source
, starting at
i
, and write it to dest
, starting at
j
.
-
encrypt(byte[], int, byte[], int)
- Encrypt a single block from
source
, starting at
i
, and write it to dest
, starting at
j
.
-
equals(Object)
- Reutns trud iff this and key are equivalent.
-
getAlgorithm()
- Return "RSA"
-
getSize()
- Return the size of the key modulo in bits.
-
isPrivate()
- Return true iff this is a private key.
-
matches(Key)
-
Returns true if this and key are a matched pair of
public/private keys.
-
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.
-
plainBlockSize()
- Returns the size of the blocks that can be encrypted in one call
to encrypt().
-
sign(Fingerprint)
- Create a signature for the fingerprint
fp
.
-
signatureSize()
- Returns the length of the signature in bytes.
-
signBlockSize()
- Returns the maximum size in bytes of the fingerprint
that can be signed.
-
toString()
- Return a CDS for this key.
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.
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
createKeys
public static KeyPair createKeys(int bitLength)
- Create a pair of public/private keys. The key modulo will be
bitLength
or bitLength-1
bits.
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.
getSize
public int getSize()
- Return the size of the key modulo in bits.
- Overrides:
- getSize in class K
getAlgorithm
public String getAlgorithm()
- Return "RSA"
- Overrides:
- getAlgorithm in class K
isPrivate
public boolean isPrivate()
- Return true iff this is a private key.
- Overrides:
- isPrivate in class K
toString
public String toString()
- Return a CDS for this key.
- Overrides:
- toString in class Object
- See Also:
- fromString
equals
public boolean equals(Object key)
- Reutns trud iff this and key are equivalent.
- Overrides:
- equals in class Object
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
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.
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.
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
.
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
.
signBlockSize
public int signBlockSize()
- Returns the maximum size in bytes of the fingerprint
that can be signed.
signatureSize
public int signatureSize()
- Returns the length of the signature in bytes.
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.
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