home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / security / KeyFactorySpi.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  4.4 KB  |  130 lines

  1. /*
  2.  * @(#)KeyFactorySpi.java    1.3 98/03/18
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.security;
  16.  
  17. import java.security.spec.KeySpec;
  18. import java.security.spec.InvalidKeySpecException;
  19.  
  20. /**
  21.  * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
  22.  * for the <code>KeyFactory</code> class.
  23.  * All the abstract methods in this class must be implemented by each 
  24.  * cryptographic service provider who wishes to supply the implementation
  25.  * of a key factory for a particular algorithm.
  26.  *
  27.  * <P> Key factories are used to convert <I>keys</I> (opaque
  28.  * cryptographic keys of type <code>Key</code>) into <I>key specifications</I>
  29.  * (transparent representations of the underlying key material), and vice
  30.  * versa.
  31.  *
  32.  * <P> Key factories are bi-directional. That is, they allow you to build an
  33.  * opaque key object from a given key specification (key material), or to
  34.  * retrieve the underlying key material of a key object in a suitable format.
  35.  *
  36.  * <P> Multiple compatible key specifications may exist for the same key.
  37.  * For example, a DSA public key may be specified using
  38.  * <code>DSAPublicKeySpec</code> or
  39.  * <code>X509EncodedKeySpec</code>. A key factory can be used to translate
  40.  * between compatible key specifications.
  41.  *
  42.  * <P> A provider should document all the key specifications supported by its
  43.  * key factory.
  44.  *
  45.  * @author Jan Luehe
  46.  *
  47.  * @version 1.3, 98/03/18
  48.  *
  49.  * @see KeyFactory
  50.  * @see Key
  51.  * @see PublicKey
  52.  * @see PrivateKey
  53.  * @see java.security.spec.KeySpec
  54.  * @see java.security.spec.DSAPublicKeySpec
  55.  * @see java.security.spec.X509EncodedKeySpec
  56.  *
  57.  * @since JDK1.2
  58.  */
  59.  
  60. public abstract class KeyFactorySpi {
  61.  
  62.     /**
  63.      * Generates a public key object from the provided key
  64.      * specification (key material).
  65.      *
  66.      * @param keySpec the specification (key material) of the public key.
  67.      *
  68.      * @return the public key.
  69.      *
  70.      * @exception InvalidKeySpecException if the given key specification
  71.      * is inappropriate for this key factory to produce a public key.
  72.      */
  73.     protected abstract PublicKey engineGeneratePublic(KeySpec keySpec)
  74.         throws InvalidKeySpecException;
  75.  
  76.     /**
  77.      * Generates a private key object from the provided key
  78.      * specification (key material).
  79.      *
  80.      * @param keySpec the specification (key material) of the private key.
  81.      *
  82.      * @return the private key.
  83.      *
  84.      * @exception InvalidKeySpecException if the given key specification
  85.      * is inappropriate for this key factory to produce a private key.
  86.      */
  87.     protected abstract PrivateKey engineGeneratePrivate(KeySpec keySpec)
  88.         throws InvalidKeySpecException;
  89.  
  90.     /**
  91.      * Returns a specification (key material) of the given key
  92.      * object.
  93.      * <code>keySpec</code> identifies the specification class in which 
  94.      * the key material should be returned. It could, for example, be
  95.      * <code>DSAPublicKeySpec.class</code>, to indicate that the
  96.      * key material should be returned in an instance of the 
  97.      * <code>DSAPublicKeySpec</code> class.
  98.      *
  99.      * @param key the key.
  100.      *
  101.      * @param keySpec the specification class in which 
  102.      * the key material should be returned.
  103.      *
  104.      * @return the underlying key specification (key material) in an instance
  105.      * of the requested specification class.
  106.  
  107.      * @exception InvalidKeySpecException if the requested key specification is
  108.      * inappropriate for the given key, or the given key cannot be dealt with
  109.      * (e.g., the given key has an unrecognized format).
  110.      */
  111.     protected abstract KeySpec engineGetKeySpec(Key key, Class keySpec)
  112.     throws InvalidKeySpecException;
  113.  
  114.     /**
  115.      * Translates a key object, whose provider may be unknown or
  116.      * potentially untrusted, into a corresponding key object of this key
  117.      * factory.
  118.      *
  119.      * @param key the key whose provider is unknown or untrusted.
  120.      *
  121.      * @return the translated key.
  122.      *
  123.      * @exception InvalidKeyException if the given key cannot be processed
  124.      * by this key factory.
  125.      */
  126.     protected abstract Key engineTranslateKey(Key key)
  127.     throws InvalidKeyException;
  128.  
  129. }
  130.