Home | History | Annotate | Download | only in crypto
      1 /*
      2  *  Licensed to the Apache Software Foundation (ASF) under one or more
      3  *  contributor license agreements.  See the NOTICE file distributed with
      4  *  this work for additional information regarding copyright ownership.
      5  *  The ASF licenses this file to You under the Apache License, Version 2.0
      6  *  (the "License"); you may not use this file except in compliance with
      7  *  the License.  You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  *  Unless required by applicable law or agreed to in writing, software
     12  *  distributed under the License is distributed on an "AS IS" BASIS,
     13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  *  See the License for the specific language governing permissions and
     15  *  limitations under the License.
     16  */
     17 
     18 package javax.crypto;
     19 
     20 import java.security.InvalidAlgorithmParameterException;
     21 import java.security.SecureRandom;
     22 import java.security.spec.AlgorithmParameterSpec;
     23 
     24 /**
     25  * The <i>Service Provider Interface</i> (<b>SPI</b>) definition for the
     26  * {@code KeyGenerator} class.
     27  *
     28  * @see KeyGenerator
     29  */
     30 public abstract class KeyGeneratorSpi {
     31 
     32     /**
     33      * Creates a new {@code KeyGeneratorSpi} instance.
     34      */
     35     public KeyGeneratorSpi() {
     36     }
     37 
     38     /**
     39      * Generates a secret key.
     40      *
     41      * @return the generated secret key.
     42      */
     43     protected abstract SecretKey engineGenerateKey();
     44 
     45     /**
     46      * Initializes this {@code KeyGeneratorSpi} instance with the specified
     47      * algorithm parameters and randomness source.
     48      *
     49      * @param params
     50      *            the parameters for the key generation algorithm.
     51      * @param random
     52      *            the randomness source for any random bytes.
     53      * @throws InvalidAlgorithmParameterException
     54      *             if the parameters cannot be uses to initialize this key
     55      *             generator algorithm.
     56      */
     57     protected abstract void engineInit(AlgorithmParameterSpec params,
     58             SecureRandom random) throws InvalidAlgorithmParameterException;
     59 
     60     /**
     61      * Initializes this {@code KeyGenerator} instance for the specified key
     62      * size (in bits) using the specified randomness source.
     63      *
     64      * @param keysize
     65      *            the size of the key (in bits).
     66      * @param random
     67      *            the randomness source for any random bytes.
     68      */
     69     protected abstract void engineInit(int keysize, SecureRandom random);
     70 
     71     /**
     72      * Initializes this {@code KeyGenerator} with the specified randomness
     73      * source.
     74      *
     75      * @param random
     76      *            the randomness source for any random bytes.
     77      */
     78     protected abstract void engineInit(SecureRandom random);
     79 }