Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## spki
Class PrivateKey

    java.lang.Object
      |
      +--spki.BaseObj
            |
            +--spki.PrivateKey

public class PrivateKey
extends BaseObj
implements Key

This class represents a private signature key object. It provides everything a user needs to employ the key for signing signatures.

Formal definition:

     <alg-id>:: <byte-string> | <uri> ;
     <pub-sig-alg-id>:: <alg-id> ;
     <pub-key-hash>:: <hash> ;
     <priv-key>:: "(" "priv-key" "(" <pub-sig-alg-id> <s-expr>+ ")" <pub-key-hash> ")" ;

The RSA-keys S-Expression must contain the following s-expressions tokens: `n` and `d`, of the form `(<token> <keydata>)`.

NOTE: algorithm-ID is implemented as String for now. NOTE: only rsa-pkcs1-sha1 is supported for now.

TODO: implement algorithm-ID as <byte-string> and <uris>.

Version:
  $Id: PrivateKey.java,v 1.13 2002/05/12 00:27:46 tep Exp $
Author:
  Tep Narula <tep@win.trlabs.ca>, adapted from SPKI.SPKIHash by Per Harald Myrvang <perm@pasta.cs.uit.no>
See Also:
  `PublicKey`, `Signature`

Field Summary
`private static String` | `__ME` This class's full name.
`private String` | `cachedKeyId` Cached key-id.
`private PrivateKey` | `jca_key` The key, used by JCA.
`private Hash` | `pub_hash` The hash of the corresponding public key.
`static String` | `SEXP_NAME` This class S-Expression type name, used by toSExpression() and other methods.
`private Signature` | `sig` Signature object used for signing.
`private String` | `sig_alg_id` Signature algorithm ID.
`private String` | `signature_provider` Signature Provider ID.

Fields inherited from class spki.BaseObj
`__ME, cache_sexp, cached_sexp, DEFAULT_HASH_ALG, locked, SEXP_NAME`

Constructor Summary
`protected` | `PrivateKey()` Don't use me!
`` | `PrivateKey(PrivateKey pk, Hash pub_hash)` Create an immutable PrivateKey from a java.security.PrivateKey object.
`` | `PrivateKey(SExpression sexp)` Create an immutable PrivateKey object from an S-Expression.

Method Summary
`String` | `getAlgId()` Get the SPKI encryption/signature algorithm id associated with the key.
`Key` | `getJCAKey()` Get a key object usable by [I]JCA packages.
`Hash` | `getKeyHash()` Get a Hash representing this key using the default hash algorithm.
`Hash` | `getKeyHash(String hashAlg)` Get a Hash representing this key using the specified hashing algorithm.
`String` | `getKeyId()` Get the key-id of this key.
`Signature` | `sign(byte[] input)` Sign a byte-array using this private key.
`Signature` | `sign(Hash hash)` Sign a Hash object using this private key.
`SExpression` | `toSExpression()` Build an SExpression representing this object.

Methods inherited from class spki.BaseObj
`disableSExpressionCaching, enableSExpressionCaching, extractHashAlgId, getCachedSExpression, isLocked, isSListOfType, lock, providerToSPKI, setCachedSExpression, spkiToProvider, toString`

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait`

Field Detail

### __ME

    private static final String __ME

  This class's full name.

### SEXP_NAME

    public static final String SEXP_NAME

  This class S-Expression type name, used by toSExpression() and other methods.
  See Also:
    `toSExpression()`

### jca_key

    private PrivateKey jca_key

  The key, used by JCA.

### sig_alg_id

    private String sig_alg_id

  Signature algorithm ID.

### signature_provider

    private String signature_provider

  Signature Provider ID.

### pub_hash

    private Hash pub_hash

  The hash of the corresponding public key.

### sig

    private Signature sig

  Signature object used for signing.

### cachedKeyId

    private String cachedKeyId

  Cached key-id.
  See Also:
    `getKeyId()`

Constructor Detail

### PrivateKey

    protected PrivateKey()

  Don't use me!
  See Also:
    `PrivateKey(SExpression)`, `PrivateKey(java.security.PrivateKey,spki.Hash)`

### PrivateKey

    public PrivateKey(SExpression sexp)
               throws SPKIException,
                      ParseException

  Create an immutable PrivateKey object from an S-Expression.
  See Also:
    `BaseObj.BaseObj(SExpression)`

### PrivateKey

    public PrivateKey(PrivateKey pk,
                      Hash pub_hash)
               throws SPKIException

  Create an immutable PrivateKey from a java.security.PrivateKey object. Note that the public signature algorithm id (<pub-sig-key-id>) defaults in the case of RSA to `rsa-pkcs1-sha1`.
  Parameters:
    `pk` - Object implementing the java.security.PrivateKey interface.
    `pub_hash` - Hash object of the corresponding public key.
  Throws:
    SPKIException - if something went wrong.

Method Detail

### toSExpression

    public SExpression toSExpression()
                              throws SPKIException

  Build an SExpression representing this object. SECURITY HOLE: this method will output all the internal information it has on this private key!
  Overrides:
    toSExpression in class BaseObj
  See Also:
    `BaseObj.toSExpression()`

### getAlgId

    public String getAlgId()

  Description copied from interface: Key
  Get the SPKI encryption/signature algorithm id associated with the key.
  Specified by:
    getAlgId in interface Key
  Tags copied from interface: Key
  Returns:
    String containing a SPKI algorithm-id.

### getJCAKey

    public Key getJCAKey()

  Description copied from interface: Key
  Get a key object usable by [I]JCA packages.
  Specified by:
    getJCAKey in interface Key
  Tags copied from interface: Key
  Returns:
    java.security.Key object implementing, or `null` if this is a private key.

### getKeyHash

    public Hash getKeyHash()

  Description copied from interface: Key
  Get a Hash representing this key using the default hash algorithm.
  Specified by:
    getKeyHash in interface Key
  Tags copied from interface: Key
  Returns:
    Hash object representing this key.
  Throws:
    SPKIException - if something went wrong

### getKeyHash

    public Hash getKeyHash(String hashAlg)

  Description copied from interface: Key
  Get a Hash representing this key using the specified hashing algorithm.
  Specified by:
    getKeyHash in interface Key
  Tags copied from interface: Key
  Parameters:
    `hashAlg` - hashing algorithm-id to use.
  Returns:
    Hash object representing this key.
  Throws:
    SPKIException - if something went wrong

### getKeyId

    public String getKeyId()
                    throws SPKIException

  Description copied from interface: Key
  Get the key-id of this key. Key-id is a Base64-encoded hash value, using the default hash algorithm.
  Specified by:
    getKeyId in interface Key
  Tags copied from interface: Key
  Returns:
    String containing the key-id, or `null`.``
  Throws:
    SPKIException - if something went wrong

### sign

    public final Signature sign(Hash hash)
                         throws SPKIException

  Sign a Hash object using this private key.
  Parameters:
    `hash` - the Hash object to be signed.
  Returns:
    Signature object containing the signature.
  Throws:
    SPKIException - if something went wrong.
  See Also:
    `Signature`

### sign

    public final Signature sign(byte[] input)
                         throws SPKIException

  Sign a byte-array using this private key. It simply hashes the input then call sign(Hash).
  Parameters:
    `input` - the byte-array to be signed.
  Returns:
    Signature object containing the signature.
  Throws:
    SPKIException - if something went wrong.
  See Also:
    `sign(Hash)`, `Signature`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD