org.logi.crypto.keys
Class RSAPublicKey

java.lang.Object
  |
  +--org.logi.crypto.Crypto
        |
        +--org.logi.crypto.keys.K
              |
              +--org.logi.crypto.keys.RSAPublicKey
All Implemented Interfaces:
BlindingKey, EncryptionKey, Key, java.security.Key, PrettyPrintable, java.security.PublicKey, java.security.interfaces.RSAKey, java.security.interfaces.RSAPublicKey, java.io.Serializable, VerificationKey

public class RSAPublicKey
extends org.logi.crypto.keys.K
implements EncryptionKey, VerificationKey, BlindingKey, java.security.interfaces.RSAPublicKey

An instance of this class handles a single public RSA key.

Author:
Logi Ragnarsson (logi@logi.org)
See Also:
Serialized Form

Fields inherited from class org.logi.crypto.Crypto
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO
 
Fields inherited from interface java.security.Key
serialVersionUID
 
Fields inherited from interface java.security.PublicKey
serialVersionUID
 
Constructor Summary
RSAPublicKey(java.math.BigInteger e, java.math.BigInteger n)
          Create a new public RSA key (e,n).
 
Method Summary
 BlindFingerprint blind(Fingerprint fp, BlindingFactor bf)
          Blind a fingerprint with a public key and the given blinding factor in preparation for blindly signing the fingerprint with the private key.
 int cipherBlockSize()
          Returns the size of the blocks that can be decrypted in one call to decrypt().
 BlindingFactor createBlindingFactor()
          Create a new blinding factor suitable for blinding a fingerprint before being signed with the private key in the pair.
 void encrypt(byte[] source, int i, byte[] dest, int j)
          Encrypt one block of data.
 boolean equals(java.lang.Object o)
          Return true iff the two keys are equivalent.
 java.lang.String getAlgorithm()
          The name of the algorithm is "RSA".
 byte[] getEncoded()
          Return encoded version.
 Fingerprint getFingerprint()
          Return the key's fingerprint using the default hash function.
 Fingerprint getFingerprint(java.lang.String algorithm)
          Return the key's fingerprint using the specified hash function.
 java.lang.String getFormat()
          Returns the name of the key-encoding format.
 java.math.BigInteger getModulus()
          Return the RSA modulus.
 java.math.BigInteger getPublicExponent()
          Return the RSA exponent.
 int getSize()
          Return the size of the key modulo in bits.
 int hashCode()
          Return a hash-code based on the keys SHA1 fingerprint.
 boolean matches(Key key)
          Check if a key mathces this.
 Fingerprint matchFingerprint()
          Returns the default fingerprint of the matching key in the key-pair.
 Fingerprint matchFingerprint(java.lang.String algorithm)
          Returns the default fingerprint of the matching key in the key-pair.
static RSAPublicKey parseCDS(java.lang.String[] param)
          Used by Crypto.fromString when parsing a CDS.
 int plainBlockSize()
          Returns the size of the blocks that can be encrypted in one call to encrypt().
 void prettyPrint(java.io.PrintWriter out, int ind, int rec)
          Print this object to out, indented with ind tabs, going down at most rec levels of recursion.
 int signatureSize()
          Returns the length of the signature in bytes.
 int signBlockSize()
          Returns the maximum size in bytes of the fingerprint that can be signed.
 java.lang.String toString()
          Return a CDS for this key.
 Signature unBlind(BlindSignature bs, BlindingFactor bf)
          Unblind a blind signature using the same blinding factor that was used to blind the original fingerprint.
 boolean verify(Signature s, Fingerprint fp)
          Verify a Signature on a Fingerprint with a public key.
 
Methods inherited from class org.logi.crypto.Crypto
binString, binString, ensureArrayLength, ensureArrayLength, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, prettyPrint, readBlock, readInt, trimArrayLength, trimArrayLength, trimLeadingZeroes, writeBytes, writeBytes, writeInt
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.logi.crypto.keys.Key
getFingerprint, getFingerprint, hashCode, matchFingerprint, matchFingerprint
 
Methods inherited from interface org.logi.crypto.io.PrettyPrintable
prettyPrint
 
Methods inherited from interface java.security.Key
getEncoded, getFormat
 

Constructor Detail

RSAPublicKey

public RSAPublicKey(java.math.BigInteger e,
                    java.math.BigInteger n)
Create a new public RSA key (e,n).
Method Detail

parseCDS

public static RSAPublicKey parseCDS(java.lang.String[] param)
                             throws InvalidCDSException
Used by Crypto.fromString when parsing a CDS.

A valid CDS can be created by calling the toString() method.

Throws:
InvalidCDSException - if the CDS is malformed.
See Also:
Crypto.fromString(String)

getSize

public int getSize()
Return the size of the key modulo in bits.
Specified by:
getSize in interface Key

getAlgorithm

public java.lang.String getAlgorithm()
The name of the algorithm is "RSA".
Specified by:
getAlgorithm in interface Key

getPublicExponent

public java.math.BigInteger getPublicExponent()
Return the RSA exponent.
Specified by:
getPublicExponent in interface java.security.interfaces.RSAPublicKey

getModulus

public java.math.BigInteger getModulus()
Return the RSA modulus.
Specified by:
getModulus in interface java.security.interfaces.RSAKey

toString

public java.lang.String toString()
Return a CDS for this key.
Overrides:
toString in class java.lang.Object
See Also:
Crypto.fromString(java.io.Reader)

prettyPrint

public void prettyPrint(java.io.PrintWriter out,
                        int ind,
                        int rec)
                 throws java.io.IOException
Print this object to out, indented with ind tabs, going down at most rec levels of recursion.
Specified by:
prettyPrint in interface PrettyPrintable
Overrides:
prettyPrint in class Crypto

equals

public boolean equals(java.lang.Object o)
Return true iff the two keys are equivalent.
Overrides:
equals in class java.lang.Object

matches

public final boolean matches(Key key)
Check if a key mathces this. This is true if this and key are a matched pair of public/private keys.
Specified by:
matches in interface Key

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.
Specified by:
plainBlockSize in interface EncryptionKey

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.
Specified by:
cipherBlockSize in interface EncryptionKey

encrypt

public void encrypt(byte[] source,
                    int i,
                    byte[] dest,
                    int j)
Encrypt one block of data. The plaintext is taken from source starting at offset i and ciphertext is written to dest, starting at offset j.

The amount of data read and written will match the values returned by plainBlockSize() and cipherBlockSize().

Specified by:
encrypt in interface EncryptionKey

signBlockSize

public int signBlockSize()
Returns the maximum size in bytes of the fingerprint that can be signed.
Specified by:
signBlockSize in interface VerificationKey

signatureSize

public int signatureSize()
Returns the length of the signature in bytes.
Specified by:
signatureSize in interface VerificationKey

verify

public boolean verify(Signature s,
                      Fingerprint fp)
               throws CryptoException
Verify a Signature on a Fingerprint with a public key.

The method returns true iff s is a signature for fp created with the mathcing private key.

Specified by:
verify in interface VerificationKey
Throws:
KeyException - if this is not a public key

createBlindingFactor

public BlindingFactor createBlindingFactor()
Create a new blinding factor suitable for blinding a fingerprint before being signed with the private key in the pair.
Specified by:
createBlindingFactor in interface BlindingKey

blind

public BlindFingerprint blind(Fingerprint fp,
                              BlindingFactor bf)
                       throws KeyException
Blind a fingerprint with a public key and the given blinding factor in preparation for blindly signing the fingerprint with the private key.
Specified by:
blind in interface BlindingKey
Throws:
KeyException - if you try to blind with a private key
KeyException - if the BlindingFactor is not an RSABlindingFactor

unBlind

public Signature unBlind(BlindSignature bs,
                         BlindingFactor bf)
                  throws KeyException
Unblind a blind signature using the same blinding factor that was used to blind the original fingerprint.
Specified by:
unBlind in interface BlindingKey
Throws:
KeyException - if there are problems, depending on the implementing class.

getFingerprint

public final Fingerprint getFingerprint()
Return the key's fingerprint using the default hash function.
Specified by:
getFingerprint in interface Key

getFingerprint

public final Fingerprint getFingerprint(java.lang.String algorithm)
                                 throws InvalidCDSException
Return the key's fingerprint using the specified hash function.
Specified by:
getFingerprint in interface Key
Throws:
InvalidCDSException - if the specified hash function is not available.

matchFingerprint

public Fingerprint matchFingerprint()
Returns the default fingerprint of the matching key in the key-pair.
Specified by:
matchFingerprint in interface Key

matchFingerprint

public Fingerprint matchFingerprint(java.lang.String algorithm)
                             throws InvalidCDSException
Returns the default fingerprint of the matching key in the key-pair.
Specified by:
matchFingerprint in interface Key
Throws:
InvalidCDSException - if the specified hash function is not available.

hashCode

public final int hashCode()
Return a hash-code based on the keys SHA1 fingerprint.
Specified by:
hashCode in interface Key
Overrides:
hashCode in class java.lang.Object

getEncoded

public byte[] getEncoded()
Return encoded version.
Specified by:
getEncoded in interface java.security.Key

getFormat

public java.lang.String getFormat()
Returns the name of the key-encoding format.
Specified by:
getFormat in interface java.security.Key


Copyright (c) 1997-2001 Logi Ragnarsson - Distributed under the GPL