/[classpath]/classpath/java/security/KeyPairGenerator.java
ViewVC logotype

Diff of /classpath/java/security/KeyPairGenerator.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.8 by raif, Sun Mar 9 07:14:00 2003 UTC revision 1.9 by cbj, Thu Mar 27 03:32:08 2003 UTC
# Line 106  import java.security.spec.AlgorithmParam Line 106  import java.security.spec.AlgorithmParam
106   * service providers who wish to supply their own implementations of key pair   * service providers who wish to supply their own implementations of key pair
107   * generators.</p>   * generators.</p>
108   *   *
109   * @author Mark Benvenuto   * @see Signature
110     * @see KeyPair
111   * @see AlgorithmParameterSpec   * @see AlgorithmParameterSpec
112     * @author Mark Benvenuto
113     * @author Casey Marshall
114   */   */
115  public abstract class KeyPairGenerator extends KeyPairGeneratorSpi  public abstract class KeyPairGenerator extends KeyPairGeneratorSpi
116  {  {
117      /** The service name for key pair generators. */
118      private static final String KEY_PAIR_GENERATOR = "KeyPairGenerator";
119    
120    Provider provider;    Provider provider;
121    private String algorithm;    private String algorithm;
122    
123    /**    /**
124     * Creates a <code>KeyPairGenerator</code> object for the specified algorithm.     * Creates a <code>KeyPairGenerator</code> object for the specified
125       * algorithm.
126     *     *
127     * @param algorithm the standard string name of the algorithm. See Appendix A     * @param algorithm the standard string name of the algorithm.
128     * in the Java Cryptography Architecture API Specification &amp; Reference for     * See Appendix A in the Java Cryptography Architecture API
129     * information about standard algorithm names.     * Specification &amp; Reference for information about standard
130       * algorithm names.
131     */     */
132    protected KeyPairGenerator(String algorithm)    protected KeyPairGenerator(String algorithm)
133    {    {
# Line 171  public abstract class KeyPairGenerator e Line 179  public abstract class KeyPairGenerator e
179    }    }
180    
181    /**    /**
182     * Generates a <code>KeyPairGenerator</code> object implementing the specified     * Generates a <code>KeyPairGenerator</code> object implementing the
183     * algorithm, as supplied from the specified provider, if such an algorithm is     * specified algorithm, as supplied from the specified provider, if
184     * available from the provider.     * such an algorithm is available from the provider.
185     *     *
186     * @param algorithm the standard string name of the algorithm. See Appendix A     * @param algorithm the standard string name of the algorithm. See
187     * in the Java Cryptography Architecture API Specification &amp; Reference for     * Appendix A in the Java Cryptography Architecture API Specification
188     * information about standard algorithm names.     * &amp; Reference for information about standard algorithm names.
189     * @param provider the string name of the provider.     * @param provider the string name of the provider.
190     * @return the new <code>KeyPairGenerator</code> object.     * @return the new <code>KeyPairGenerator</code> object.
191     * @throws NoSuchAlgorithmException if the algorithm is not available from the     * @throws NoSuchAlgorithmException if the algorithm is not available
192     * provider.     * from the provider.
193     * @throws NoSuchProviderException if the provider is not available in the     * @throws NoSuchProviderException if the provider is not available in the
194     * environment.     * environment.
195     * @throws IllegalArgumentException if the provider name is <code>null</code>     * @throws IllegalArgumentException if the provider name is <code>null</code>
# Line 216  public abstract class KeyPairGenerator e Line 224  public abstract class KeyPairGenerator e
224     * @since 1.4     * @since 1.4
225     * @see Provider     * @see Provider
226     */     */
227    public static KeyPairGenerator getInstance(String algorithm, Provider provider)    public static KeyPairGenerator getInstance(String algorithm,
228                                                 Provider provider)
229      throws NoSuchAlgorithmException      throws NoSuchAlgorithmException
230    {    {
231      if (provider == null)      if (provider == null)
232        throw new IllegalArgumentException();        throw new IllegalArgumentException("Illegal provider");
233    
234      // try the name as is      Object o = Engine.getInstance(KEY_PAIR_GENERATOR, algorithm, provider);
235      String className = provider.getProperty("KeyPairGenerator." + algorithm);      KeyPairGenerator result = null;
236      if (className == null) // try all uppercase      if (o instanceof KeyPairGeneratorSpi)
       {  
         String upper = algorithm.toUpperCase();  
         className = provider.getProperty("KeyPairGenerator." + upper);  
         if (className == null) // try if it's an alias  
           {  
             String alias = provider.getProperty(  
                 "Alg.Alias.KeyPairGenerator." + algorithm);  
             if (alias == null) // try all-uppercase alias name  
               {  
                 alias = provider.getProperty(  
                     "Alg.Alias.KeyPairGenerator." + upper);  
                 if (alias == null) // spit the dummy  
                   throw new NoSuchAlgorithmException(algorithm);  
               }  
             className = provider.getProperty("KeyPairGenerator." + alias);  
             if (className == null)  
               throw new NoSuchAlgorithmException(algorithm);  
           }  
       }  
     return getInstance(className, algorithm, provider);  
   }  
   
   private static KeyPairGenerator getInstance(String classname,  
                                               String algorithm,  
                                               Provider provider)  
     throws NoSuchAlgorithmException  
   {  
     try  
       {  
         Object o = Class.forName(classname).newInstance();  
         KeyPairGenerator kpg;  
         if (o instanceof KeyPairGeneratorSpi)  
           kpg = new DummyKeyPairGenerator((KeyPairGeneratorSpi) o, algorithm);  
         else  
           {  
             kpg = (KeyPairGenerator) o;  
             kpg.algorithm = algorithm;  
           }  
   
         kpg.provider = provider;  
         return kpg;  
       }  
     catch (ClassNotFoundException cnfe)  
       {  
         throw new NoSuchAlgorithmException("Class not found");  
       }  
     catch (InstantiationException ie)  
237        {        {
238          throw new NoSuchAlgorithmException("Class instantiation failed");          result = new DummyKeyPairGenerator((KeyPairGeneratorSpi) o, algorithm);
239        }        }
240      catch (IllegalAccessException iae)      else if (o instanceof KeyPairGenerator)
241        {        {
242          throw new NoSuchAlgorithmException("Illegal Access");          result = (KeyPairGenerator) o;
243            result.algorithm = algorithm;
244        }        }
245        result.provider = provider;
246        return result;
247    }    }
248    
249    /**    /**

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26