wtanaka.praya.gale
Class GalePublicKey

java.lang.Object
  |
  +--wtanaka.praya.gale.GalePublicKey
All Implemented Interfaces:
java.security.Key, java.security.PublicKey, java.io.Serializable

public class GalePublicKey
extends java.lang.Object
implements java.security.PublicKey

Represents a public key.

Return to Sourceforge or the Praya Homepage

Version:
$Name: $ $Date: 2002/03/25 02:09:03 $
Author:
$Author: wtanaka $
See Also:
Serialized Form

Field Summary
static int DA_MD2
           
static int DA_MD5
           
static byte[] DIGEST_INFO_A
           
static int DIGEST_INFO_A_LEN
           
static byte[] DIGEST_INFO_B
           
static int DIGEST_INFO_B_LEN
           
static int DIGEST_INFO_LEN
           
(package private)  int m_bits
           
(package private)  Timestamp m_expireDate
           
(package private)  FragmentList m_fragments
           
(package private)  java.lang.String m_id
           
(package private)  int m_originalStreamVersion
           
(package private)  java.lang.String m_owner
           
(package private)  java.math.BigInteger m_rsaExponent
           
(package private)  java.math.BigInteger m_rsaModulus
           
(package private)  byte[] m_signature
           
(package private)  Timestamp m_signedDate
           
static int MAX_DIGEST_LEN
           
static int MAX_RSA_MODULUS_BITS
           
static int MAX_RSA_MODULUS_LEN
           
static int MAX_RSA_PRIME_BITS
           
static int MAX_RSA_PRIME_LEN
           
static int MAX_SIGNATURE_LEN
           
static int MIN_RSA_MODULUS_BITS
           
private static long RSA_F4
           
 
Fields inherited from interface java.security.PublicKey
serialVersionUID
 
Constructor Summary
  GalePublicKey(java.io.File f)
          Convenience Constructor which reads in from a file
  GalePublicKey(GaleInputStream in)
          Constructor which reads in from a file
(package private) GalePublicKey(java.lang.String id)
          package visible constructor which constructs a key suitable for stub export.
  GalePublicKey(java.lang.String owner, java.lang.String id, int bits, java.math.BigInteger rsaModulus, java.math.BigInteger rsaExponent)
          Constructor for a newly generated key.
 
Method Summary
private static byte[] encodeDigestInfo(byte[] digest, int digestAlgorithm)
           
 void exportStub(GaleOutputStream gout, int version)
          exports EXPORT_STUB format, for the given version Stub lengths: * Version 2:
4 // magic
+ 4 // id length
+ m_id.length()*2 // id length Locks the output stream with synchronized (gout)
 java.lang.String getAlgorithm()
           
 java.lang.String getBackwardID()
          Gets the ID of this key in reversed order (most specific key part first).
 int getBits()
           
 byte[] getEncoded()
           
 java.lang.String getFormat()
           
 FragmentList getFragmentList()
           
 java.lang.String getID()
          Deprecated. use getBackwardID instead
 java.lang.String getKeyMember()
          If the key.member field exists, this method returns the content of that fragment.
 Location getLocation()
           
 java.math.BigInteger getModulus()
           
 java.lang.String getOwner()
          Gets the owner of this key ("comment" in v1 format, "comment" in v2 format, "key.owner" in v3 format)
 java.math.BigInteger getPublicExponent()
           
 Location getRedirectTarget()
          If the key.redirect field exists, this method returns the merged location that this key points at.
 int getStreamLength()
          Convenience method which gets the stream length for this public key using the stream version this was originally constructed with.
 int getStreamLength(int version)
           
private  byte[] publicBlock(byte[] input)
           
 java.math.BigInteger publicDecrypt(byte[] input)
          public decrypt
(package private)  byte[] publicEncrypt(byte[] input)
           
 GalePublicKey sign(GalePrivateKey priv)
           
 java.lang.String toString()
           
 void verify(byte[] signature, byte[] message)
          Verify that the given message, when signed with the private key corresponding to this key, produces the given signature.
 void write(GaleOutputStream gout)
          Convenience method which writes this public key to the given stream using the stream version this was originally constructed with.
 void write(GaleOutputStream gout, int version)
          Writes the public key to the stream with the given stream version.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

DA_MD2

public static final int DA_MD2

DA_MD5

public static final int DA_MD5

RSA_F4

private static final long RSA_F4

MIN_RSA_MODULUS_BITS

public static final int MIN_RSA_MODULUS_BITS

MAX_RSA_MODULUS_BITS

public static final int MAX_RSA_MODULUS_BITS

MAX_RSA_MODULUS_LEN

public static final int MAX_RSA_MODULUS_LEN

MAX_RSA_PRIME_BITS

public static final int MAX_RSA_PRIME_BITS

MAX_RSA_PRIME_LEN

public static final int MAX_RSA_PRIME_LEN

MAX_DIGEST_LEN

public static final int MAX_DIGEST_LEN

DIGEST_INFO_A

public static final byte[] DIGEST_INFO_A

DIGEST_INFO_A_LEN

public static final int DIGEST_INFO_A_LEN

DIGEST_INFO_B

public static byte[] DIGEST_INFO_B

DIGEST_INFO_B_LEN

public static final int DIGEST_INFO_B_LEN

DIGEST_INFO_LEN

public static final int DIGEST_INFO_LEN

MAX_SIGNATURE_LEN

public static final int MAX_SIGNATURE_LEN

m_id

java.lang.String m_id

m_bits

int m_bits

m_owner

java.lang.String m_owner

m_rsaExponent

java.math.BigInteger m_rsaExponent

m_rsaModulus

java.math.BigInteger m_rsaModulus

m_signedDate

Timestamp m_signedDate

m_expireDate

Timestamp m_expireDate

m_fragments

FragmentList m_fragments

m_signature

byte[] m_signature

m_originalStreamVersion

int m_originalStreamVersion
Constructor Detail

GalePublicKey

public GalePublicKey(java.io.File f)
              throws java.io.IOException
Convenience Constructor which reads in from a file

GalePublicKey

public GalePublicKey(GaleInputStream in)
              throws java.io.IOException
Constructor which reads in from a file

GalePublicKey

GalePublicKey(java.lang.String id)
package visible constructor which constructs a key suitable for stub export.

GalePublicKey

public GalePublicKey(java.lang.String owner,
                     java.lang.String id,
                     int bits,
                     java.math.BigInteger rsaModulus,
                     java.math.BigInteger rsaExponent)
Constructor for a newly generated key.
Method Detail

sign

public GalePublicKey sign(GalePrivateKey priv)
                   throws java.security.NoSuchAlgorithmException

getID

public java.lang.String getID()
Deprecated. use getBackwardID instead


getBackwardID

public java.lang.String getBackwardID()
Gets the ID of this key in reversed order (most specific key part first).

exportStub

public void exportStub(GaleOutputStream gout,
                       int version)
                throws java.io.IOException
exports EXPORT_STUB format, for the given version Stub lengths: Locks the output stream with synchronized (gout)
Parameters:
gout - the output stream on which to export the stub key.
version - should be "2"
Throws:
java.lang.IllegalArgumentException - if version != 2

getStreamLength

public int getStreamLength(int version)

write

public void write(GaleOutputStream gout,
                  int version)
           throws java.io.IOException,
                  NotEnoughInfoException
Writes the public key to the stream with the given stream version. Locks the stream with synchronized (gout).
Parameters:
gout - the output stream to write to
version - the key file format version to use when writing this key
Throws:
NotEnoughInfoException - if this is a stub key. Use exportStub instead.
java.io.IOException - if any write to the stream throws IOException

getStreamLength

public int getStreamLength()
Convenience method which gets the stream length for this public key using the stream version this was originally constructed with.

write

public void write(GaleOutputStream gout)
           throws java.io.IOException,
                  NotEnoughInfoException
Convenience method which writes this public key to the given stream using the stream version this was originally constructed with.
Parameters:
gout - the output stream to write to
Throws:
NotEnoughInfoException - if this is a stub key. Use exportStub instead.
java.io.IOException - if any write to the stream throws IOException

getAlgorithm

public java.lang.String getAlgorithm()
Specified by:
getAlgorithm in interface java.security.Key

getFormat

public java.lang.String getFormat()
Specified by:
getFormat in interface java.security.Key

getEncoded

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

verify

public void verify(byte[] signature,
                   byte[] message)
            throws AuthException,
                   InvalidKeyFormatException
Verify that the given message, when signed with the private key corresponding to this key, produces the given signature.
See Also:
GalePrivateKey.sign(byte[])

encodeDigestInfo

private static byte[] encodeDigestInfo(byte[] digest,
                                       int digestAlgorithm)

publicBlock

private byte[] publicBlock(byte[] input)

publicEncrypt

byte[] publicEncrypt(byte[] input)
               throws InvalidKeyFormatException

publicDecrypt

public java.math.BigInteger publicDecrypt(byte[] input)
                                   throws InvalidKeyFormatException,
                                          AuthException
public decrypt

getFragmentList

public FragmentList getFragmentList()

getBits

public int getBits()

getRedirectTarget

public Location getRedirectTarget()
If the key.redirect field exists, this method returns the merged location that this key points at. If the key.redirect field does not exist, return null.

getLocation

public Location getLocation()

getKeyMember

public java.lang.String getKeyMember()
If the key.member field exists, this method returns the content of that fragment. If the key.member field does not exist, return null

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getModulus

public java.math.BigInteger getModulus()

getPublicExponent

public java.math.BigInteger getPublicExponent()

getOwner

public java.lang.String getOwner()
Gets the owner of this key ("comment" in v1 format, "comment" in v2 format, "key.owner" in v3 format)